如何使用适用于 Android 的 Phonegap SoftKeyboard 插件? [英] How to use Phonegap SoftKeyboard Plugin for Android?
问题描述
我正在使用 Phonegap 开发 Android 应用程序.我需要使软键盘以编程方式出现.我正在使用 此处 的 SoftKeyboard 插件.谁能告诉我如何正确地包含这个插件 &让它起作用?我已经尝试了 Phonegap Wiki,但插件不起作用.
I am developing an Android application using Phonegap. I need to make the softkeyboard appear programatically. I am using the SoftKeyboard plugin which is found here. Can anyone tell me how to properly include this plugin & make it work? I have tried the tutorial found on the Phonegap Wiki, but the plugin is not working.
[更新]我已将插件添加到路径中
[Update] I have added the plugin to the path
com/zenexity/SoftKeyBoardPlugin/SoftKeyBoard.java
更新了 plugins.xml
并包含了
<plugin name="SoftKeyBoard" value="com.zenexity.SoftKeyBoardPlugin.SoftKeyBoard"/>
然后在www
文件夹中添加softkeyboard.js
,然后在index.html
Then in the www
folder added softkeyboard.js
, and the following in index.html
plugins.SoftKeyBoard.show(function () {
// success
},function () {
// fail
});
但没有任何反应,键盘没有显示..
But nothing happens, the keyboard is not displaying..
推荐答案
这就是我让 SoftKeyBoard 在我的应用程序中工作的方式.
This is how I got SoftKeyBoard working in my application.
DroidGap 侧
- 使用提供的 SoftKeyBoard.java 文件创建/src/com/phonegap/plugins/SoftKeyboard
添加到/res/xml/plugins.xml:
- create /src/com/phonegap/plugins/SoftKeyboard with provided file SoftKeyBoard.java inside
add to /res/xml/plugins.xml:
<代码><插件名称="SoftKeyBoard" value="com.phonegap.plugins.SoftKeyboard.SoftKeyBoard"/>
/assets/www
侧面
/assets/www
Side
- 将提供的文件 softkeyboard.js 添加到/assets/www/js
在包含 phonegap javascript 之后,在包含其他 javascript 的头部添加到 index.html:
- add provided file softkeyboard.js to /assets/www/js
add to index.html in the head where your other javascripts are included after you have included the phonegap javascript:
<代码><脚本类型="text/javascript" charset="utf-8" src="js/softkeyboard.js"></script>
然后,如果您在设备上或使用 Ripple 之类的东西,则可以调用以下内容:
You can then call the following if you are on device or using something like Ripple:
window.plugins.SoftKeyBoard.show(function () {
// success
},function () {
// fail
});
或者类似的东西,如果你想确保命名空间可用,这将防止未定义的问题:
or something like this if you want to make sure the namespace is available, which will prevent undefined problems:
((((window || {}).plugins || {}).SoftKeyBoard || {}).show || function(){})();
我想也许你出错的地方是没有在 index.html 的头部包含 js/softkeyboard.js.
I think maybe where you went wrong was not including the js/softkeyboard.js in your head of index.html.
希望对你有帮助
这篇关于如何使用适用于 Android 的 Phonegap SoftKeyboard 插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!