How to use Phonegap SoftKeyboard Plugin for Android?

前端 未结 5 1516
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 00:31

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 an

相关标签:
5条回答
  • 2020-12-05 01:08

    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
    });
    
    0 讨论(0)
  • 2020-12-05 01:09

    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);
    
    0 讨论(0)
  • 2020-12-05 01:14

    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 });
    0 讨论(0)
  • 2020-12-05 01:20

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

    SoftKeyboardPlugin by Simon McDonald

    0 讨论(0)
  • 2020-12-05 01:32

    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

    0 讨论(0)
提交回复
热议问题