Cordova 3.4 - 检测键盘事件

Sch*_*pse 11 keyboard jquery events android cordova

我想检测showkeyboardhidekeyboard事件在运行感谢科尔多瓦3.4.0和jQuery Mobile的1.4.2我的应用程序.在配置文件中,fullscreen属性设置为true(我需要它).

事实是,在LogCat中,我无法阅读(显然这是由于全屏模式):

SoftKeyboardDetect:忽略此事件

是否有任何解决方案来检测这两个事件?我通过检测输入字段上的模糊和焦点事件尝试了另一种方法.它可以工作,但是当后退按钮关闭键盘时,不会调用这些事件.

所以,我试图检测后退按钮事件,但它不起作用(http://simonmacdonald.blogspot.fr/2011/05/overriding-back-button-in-phonegap.html).

Ros*_*oss 19

我认为这将满足您的需求 -

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');
}
Run Code Online (Sandbox Code Playgroud)

//编辑

由于你无法挂钩这些事件,你需要一个插件. 这个在这里就可以了.

要安装插件执行 cordova plugin add 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');
}
Run Code Online (Sandbox Code Playgroud)


And*_*eas 5

离子键盘插件让你native.showkeyboard并且可以使用这种方式native.hidekeyboard事件:将它添加到你后项目:

cordova plugin add https://github.com/driftyco/ionic-plugins-keyboard.git
Run Code Online (Sandbox Code Playgroud)

用这种方式:

window.addEventListener('native.hidekeyboard', keyboardHideHandler);
window.addEventListener('native.showkeyboard', keyboardShowHandler);
function keyboardHideHandler(e){
    alert('Goodnight, sweet prince');
}
function keyboardShowHandler(e){
    alert('Keyboard height is: ' + e.keyboardHeight);
}
Run Code Online (Sandbox Code Playgroud)

可以在github上找到额外的描述和功能 这在Cordova 3.4中适用于我,在config.xml文件中配置了全屏模式.它有15036次下载这一事实说明了很多,但正如我所说,我也在全屏显示确切的Cordova版本.(它实际上是唯一对我有用的东西加上它也支持ios)