javascript 如何使用适用于 Android 的 Phonegap SoftKeyboard 插件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9060658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Phonegap SoftKeyboard Plugin for Android?
提问by NBK
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.
我正在使用Phonegap开发 Android 应用程序。我需要使软键盘以编程方式出现。我正在使用此处找到的 SoftKeyboard 插件。谁能告诉我如何正确包含此插件并使其工作?我已尝试在Phonegap Wiki上找到的教程,但该插件不起作用。
[Update]I have added the plugin to the path
[更新]我已将插件添加到路径中
com/zenexity/SoftKeyBoardPlugin/SoftKeyBoard.java
com/zenexity/SoftKeyBoardPlugin/SoftKeyBoard.java
Updated plugins.xml
and included
更新plugins.xml
并包含
<plugin name="SoftKeyBoard" value="com.zenexity.SoftKeyBoardPlugin.SoftKeyBoard"/>
Then in the www
folder added softkeyboard.js
, and the following in index.html
然后在www
文件夹中添加softkeyboard.js
,然后在index.html
plugins.SoftKeyBoard.show(function () {
// success
},function () {
// fail
});
But nothing happens, the keyboard is not displaying..
但是没有任何反应,键盘没有显示..
采纳答案by darryn.ten
This is how I got SoftKeyBoard working in my application.
这就是我让 SoftKeyBoard 在我的应用程序中工作的方式。
DroidGap Side
DroidGap 侧
- create /src/com/phonegap/plugins/SoftKeyboard with provided file SoftKeyBoard.java inside
add to /res/xml/plugins.xml:
< plugin name="SoftKeyBoard" value="com.phonegap.plugins.SoftKeyboard.SoftKeyBoard" />
- 使用提供的文件 SoftKeyBoard.java 创建 /src/com/phonegap/plugins/SoftKeyboard
添加到/res/xml/plugins.xml:
< plugin name="SoftKeyBoard" value="com.phonegap.plugins.SoftKeyboard.SoftKeyBoard" />
/assets/www
Side
/assets/www
边
- 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:
< script type="text/javascript" charset="utf-8" src="js/softkeyboard.js"></script>
- 将提供的文件 softkeyboard.js 添加到 /assets/www/js
在包含 phonegap javascript 后,在包含其他 javascript 的头部添加 index.html:
< script type="text/javascript" charset="utf-8" src="js/softkeyboard.js"></script>
You can then call the following if you are on device or using something like Ripple:
然后,如果您在设备上或使用 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(){})();
I think maybe where you went wrong was not including the js/softkeyboard.js in your head of index.html.
我想也许你出错的地方是没有在 index.html 的头部包含 js/softkeyboard.js。
Hope this helps you
希望这对你有帮助
回答by originalgremlin
For the latest version of PhoneGap (Apache Cordova 2.1.0) I had to do the following:
对于最新版本的 PhoneGap(Apache Cordova 2.1.0),我必须执行以下操作:
Installed these plugin sources which reflected the project name change: https://github.com/originalgremlin/phonegap-plugins/tree/master/Android/SoftKeyboard
安装了这些反映项目名称更改的插件源:https: //github.com/originalgremlin/phonegap-plugins/tree/master/Android/SoftKeyboard
- Copy softkeyboard.js to your javascript library directory.
- Copy SoftKeyBoard.java to src/org/apache/cordova/plugins/SoftKeyBoard.java
- 将 softkeyboard.js 复制到您的 javascript 库目录。
- 将 SoftKeyBoard.java 复制到 src/org/apache/cordova/plugins/SoftKeyBoard.java
Put this in your HTML file, after including the cordova.js file:
在包含 cordova.js 文件后,将其放入您的 HTML 文件中:
<script src="/path/to/javascripts/softkeyboard.js"></script>
Add this to the bottom of the res/xml/config.xml plugins section:
将此添加到 res/xml/config.xml 插件部分的底部:
<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />
Now, assuming this HTML:
现在,假设这个 HTML:
<button id="keyboard">Toggle Keyboard</button>
This jQuery should do something useful:
这个 jQuery 应该做一些有用的事情:
var softkeyboard = window.cordova.plugins.SoftKeyBoard;
$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);
回答by James Harris
Try it like this:
像这样尝试:
SoftKeyBoard.show(function () {
// success
},function () {
// fail
});
The code in the JS file does not put it in the "plugins" namespace.
JS文件中的代码并没有把它放在“plugins”命名空间中。
Orjust use the PhoneGap plugins full namespace:
或者只是使用 PhoneGap 插件的完整命名空间:
window.plugins.SoftKeyBoard.show(function () {
// success
},function () {
// fail
});
回答by Nullify
go through the link. here is the full project:--
通过链接。这是完整的项目:--
回答by Maj0rPaine
Cordova 3.0 + JQM 1.3.2:Changing "fullscreen" to "false" in config.xml fixed the "adjustPan" and prevented my inputs from being covered when the keyboard displayed. However, blur() would not close the keyboard and this plugin worked wonderfully.
Cordova 3.0 + JQM 1.3.2:在 config.xml 中将“全屏”更改为“false”修复了“adjustPan”并防止我的输入在键盘显示时被覆盖。然而,blur() 不会关闭键盘,这个插件运行得非常好。
For the almost latest version of phonegap:
对于几乎最新版本的phonegap:
- Add SoftKeyBoard.java to your app package in src
- Add softkeyboard.js to assets/www
- Update config.xml with:
<feature name="SoftKeyBoard"><param name="android-package" value="com.yourAppPackage" /></feature>
- Call your plugin:
plugins.SoftKeyBoard.hide(function() {//success }, function() {//fail });
- 将 SoftKeyBoard.java 添加到 src 中的应用程序包
- 将 softkeyboard.js 添加到 assets/www
- 使用以下内容更新 config.xml:
<feature name="SoftKeyBoard"><param name="android-package" value="com.yourAppPackage" /></feature>
- 调用你的插件:
plugins.SoftKeyBoard.hide(function() {//success }, function() {//fail });