1
我用离子框架并在android 4.4中构建一个应用程序。 当我在某个视图上放置一个输入字段并在其中进行焦点时,键盘显示,但是当我按下硬件后退按钮时,我希望它隐藏键盘,但它会关闭当前视图并返回历史视图,我该如何让它隐藏键盘并且不要关闭当前的视图页面?如果焦点不在输入栏中,那么按回退键让它关闭当前视图是正常的。android 4.4离子硬件按钮后退关闭键盘
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
// StatusBar.styleDefault();
StatusBar.styleBlackOpaque();
}
});
$ionicPlatform.registerBackButtonAction(function (e) {
e.preventDefault();
console.log("aaaaaa:"+$cordovaKeyboard.isVisible());
function showConfirm() {
var confirmPopup = $ionicPopup.confirm({
title: '<strong>exit?</strong>',
template: 'exit?',
okText: 'exit',
cancelText: 'cancel'
});
confirmPopup.then(function (res) {
if (res) {
ionic.Platform.exitApp();
} else {
}
});
}
if ($location.path() == '/app/home') {
showConfirm();
} else
if ($ionicHistory.backView()) {
if($cordovaKeyboard.isVisible()) {
$cordovaKeyboard.close();
} else {
$ionicHistory.goBack();
}
} else {
showConfirm();
}
return false;
}, 101);
$ cordovaKeyboard.isVisible()在$ ionicPlatform.registerBackButtonAction常是返回false()。