Cordova 3.4 - Detect keyboard event(Cordova 3.4 - 检测键盘事件)
问题描述
由于 Cordova 3.4.0 和 JQuery Mobile 1.4.2,我正在尝试在我的应用程序中检测 showkeyboard
和 hidekeyboard
事件.在配置文件中,全屏属性设置为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.
所以,我尝试检测后退按钮事件,但它不起作用(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 插件添加 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 - 检测键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Cordova 3.4 - 检测键盘事件
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01