由于Cordova 3.4.0和JQuery Mobile 1.4.2,我正在尝试检测我的应用程序中的showkeyboard和hidekeyboard事件.在配置文件中,fullscreen属性设置为true(我需要它).
事实是,在LogCat中,我无法阅读(显然这是由于全屏模式):
SoftKeyboardDetect : Ignore this event
是否有任何解决方案来检测这两个事件?我通过检测输入字段上的模糊和焦点事件尝试了另一种方法.它可以工作,但是当后退按钮关闭键盘时,不会调用这些事件.
所以,我试图检测后退按钮事件,但它不起作用(http://simonmacdonald.blogspot.fr/2011/05/overriding-back-button-in-phonegap.html).
解决方法:
我认为这将满足您的需求 –
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady () {
document.addEventListener('hidekeyboard', onKeyboardHide, false);
document.addEventListener('showkeyboard', onKeyboardShow, false);
}
function onKeyboardHide() {
console.log('onKeyboardHide');
}
function onKeyboardShow() {
console.log('onKeyboardShow');
}
//编辑
由于你无法挂钩这些事件,你需要一个插件. This one here will do the trick.
要安装插件,请执行cordova插件添加com.ionic.keyboard
// This event fires when the keyboard will be shown
window.addEventListener('native.keyboardshow', keyboardShowHandler);
function keyboardShowHandler(e){
console.log('Keyboard height is: ' + e.keyboardHeight);
}
// This event fires when the keyboard will hide
window.addEventListener('native.keyboardhide', keyboardHideHandler);
function keyboardHideHandler(e){
console.log('Goodnight, sweet prince');
}