Cordova 3.4 - 检测键盘事件 [英] Cordova 3.4 - Detect keyboard event

查看:779
本文介绍了Cordova 3.4 - 检测键盘事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测在我的应用程序运行感谢科尔多瓦3.4.0的 showkeyboard hidekeyboard 和JQuery Mobile 1.4.2。在配置文件中,fullscreen属性设置为true(我需要它)。

I'm trying to detect the showkeyboard and hidekeyboard events in my application running thanks to Cordova 3.4.0 and JQuery Mobile 1.4.2. In the configuration file, the fullscreen attribute is set to true (I need it).

事实是,在LogCat中,我无法读取全屏模式):

The fact is, in LogCat, I can't read (apprently it's due to the fullscreen mode) :


SoftKeyboardDetect:忽略此事件

SoftKeyboardDetect : Ignore this event

有没有什么解决方案来检测这两个事件?我尝试了另一种方法,通过检测我的输入字段上的模糊和聚焦事件。它工作,但是当键盘被后退按钮关闭时,这些事件不被调用。

Is there any solution to detect these two events? I tried an alternative way by detecting blur and focus events on my input field. It works, but when the keyboard is closed by the back button, those events are not called.

所以,我试图检测backbutton事件,但它不工作( http://simonmacdonald.blogspot.fr/ 2011/05 / overriding-back-button-in-phonegap.html )。

So, I tried to detect the backbutton event, but it doesn't work (http://simonmacdonald.blogspot.fr/2011/05/overriding-back-button-in-phonegap.html).

推荐答案

为您的需要工作 -

I think this will work for your needs -

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');
}

//编辑

因为你不能挂钩到这些事件,你需要一个插件。 这里的一切都会做到的。

Since you cannot hook into those events you need a plugin. This one here will do the trick.

要安装插件,请执行 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');
}

这篇关于Cordova 3.4 - 检测键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆