Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

javascript - How to use Phonegap SoftKeyboard Plugin for Android?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...