如何使用 Android 版 Phonegap 软键盘插件?

发布于 2024-12-31 23:26:25 字数 902 浏览 1 评论 0原文

我正在使用 Phonegap 开发 Android 应用程序。我需要使软键盘以编程方式出现。我正在使用 SoftKeyboard 插件,可以在此处找到。谁能告诉我如何正确包含这个插件&让它发挥作用吗?我已尝试在 Phonegap Wiki,但该插件无法正常工作。

[更新] 我已将插件添加到路径

com/zenexity/SoftKeyBoardPlugin/SoftKeyBoard.java

更新了 plugins.xml 并包含

<plugin name="SoftKeyBoard" value="com.zenexity.SoftKeyBoardPlugin.SoftKeyBoard"/>

在中www 文件夹添加了 softkeyboard.js,并在 index.html 中添加了以下内容,

plugins.SoftKeyBoard.show(function () {
    // success
},function () {
   // fail
});

但没有任何反应,键盘没有显示。

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

Updated plugins.xml and included

<plugin name="SoftKeyBoard" value="com.zenexity.SoftKeyBoardPlugin.SoftKeyBoard"/>

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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

坏尐絯℡ 2025-01-07 23:26:25

这就是我让 SoftKeyBoard 在我的应用程序中工作的方式。

DroidGap Side

  • 使用提供的文件 SoftKeyBoard.java 创建 /src/com/phonegap/plugins/SoftKeyboard
  • 添加到 /res/xml/plugins.xml:

    <代码><插件 name="SoftKeyBoard" value="com.phonegap.plugins.SoftKeyboard.SoftKeyBoard" />

/assets/www Side

  • 添加提供的文件软键盘。 js 到 /assets/www/js
  • 在包含phonegap javascript 后添加到包含其他 javascript 的 header 中的 index.html:

    <代码>< script type="text/javascript" charset="utf-8" src="js/softkeyboard.js">

如果您在设备上或使用类似的内容,则可以调用以下命令Ripple:

window.plugins.SoftKeyBoard.show(function () {
  // success
},function () {
  // fail
});

或者类似的东西,如果你想确保命名空间可用,这将防止未定义的问题:

((((window || {}).plugins || {}).SoftKeyBoard || {}).show || function(){})();

我想你出错的地方可能是没有在你的index.html头中包含js/softkeyboard.js。

希望这对您有帮助

This is how I got SoftKeyBoard working in my application.

DroidGap Side

  • 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" />

/assets/www Side

  • 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>

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(){})();

I think maybe where you went wrong was not including the js/softkeyboard.js in your head of index.html.

Hope this helps you

云柯 2025-01-07 23:26:25

对于最新版本的 PhoneGap (Apache Cordova 2.1.0),我必须执行以下操作:

安装这些反映项目名称更改的插件源:
https://github.com/originalgremlin/phonegap-plugins/tree/master/Android/SoftKeyboard< /a>

  • 将 softkeyboard.js 复制到您的 javascript 库目录。
  • 将 SoftKeyBoard.java 复制到 src/org/apache/cordova/plugins/SoftKeyBoard.java

在包含 cordova.js 文件后,将其放入 HTML 文件中:

<script src="/path/to/javascripts/softkeyboard.js"></script>

将其添加到 res/xml/config.xml 插件部分的底部:

<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />

现在,假设这个 HTML:

<button id="keyboard">Toggle Keyboard</button>

这个 jQuery 应该做一些有用的事情:

var softkeyboard = window.cordova.plugins.SoftKeyBoard;
$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);

For the latest version of PhoneGap (Apache Cordova 2.1.0) I had to do the following:

Installed these plugin sources which reflected the project name change:
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

Put this in your HTML file, after including the cordova.js file:

<script src="/path/to/javascripts/softkeyboard.js"></script>

Add this to the bottom of the res/xml/config.xml plugins section:

<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />

Now, assuming this HTML:

<button id="keyboard">Toggle Keyboard</button>

This jQuery should do something useful:

var softkeyboard = window.cordova.plugins.SoftKeyBoard;
$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);
云淡月浅 2025-01-07 23:26:25

尝试这样:

SoftKeyBoard.show(function () {
    // success
},function () {
   // fail
});

JS文件中的代码没有将其放在“plugins”命名空间中。

或者只是使用 PhoneGap 插件完整命名空间:

window.plugins.SoftKeyBoard.show(function () {
    // success
},function () {
   // fail
});

Try it like this:

SoftKeyBoard.show(function () {
    // success
},function () {
   // fail
});

The code in the JS file does not put it in the "plugins" namespace.

Orjust use the PhoneGap plugins full namespace:

window.plugins.SoftKeyBoard.show(function () {
    // success
},function () {
   // fail
});
燃情 2025-01-07 23:26:25

Cordova 3.0 + JQM 1.3.2: 在 config.xml 中将“全屏”更改为“false”修复了“adjustPan”并防止在显示键盘时覆盖我的输入。然而,blur() 不会关闭键盘,这个插件运行得非常好。

对于最新版本的phonegap:

  • 将 SoftKeyBoard.java 添加到 src 中的应用程序包
  • 将 softkeyboard.js 添加到 asset/www
  • 使用以下内容更新 config.xml:
  • 调用您的插件:plugins .SoftKeyBoard.hide(function() {//成功 }, function() {//失败 });

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.

For the almost latest version of 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 });
橘寄 2025-01-07 23:26:25

通过链接。这是完整的项目:--

SoftKeyboardPlugin by Simon McDonald

go through the link. here is the full project:--

SoftKeyboardPlugin by Simon McDonald

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文