隐藏模糊,在phonegap中的软键盘

Eri*_*wan 5 android hide android-softkeyboard cordova

我有一个PhoneGap应用程序,它正常工作.唯一让我烦恼的是PhoneGap处理软键盘的方式; 当输入模糊时,它不会隐藏.它确实在iOS中执行此操作,但它甚至在Android中加载新页面时仍然存在.

我看了看这个:http: //wiki.phonegap.com/w/page/27915465/How%20to%20show%20and%20hide%20soft%20keyboard%20in%20Android

这个:https: //github.com/phonegap/phonegap-plugins/tree/master/Android/SoftKeyboard

但他们都不适合我,任何想法?

此致,Erik

Chr*_*ang 7

您链接的插件为我工作(具有完全相同的问题):

$("#eingabe").blur(); //for ios
var softkeyboard = window.cordova.plugins.SoftKeyBoard;
softkeyboard.hide();
Run Code Online (Sandbox Code Playgroud)

您可能使用过Cordova 2.0.0(或更高版本)并且没有修改插件文件(为Phonegap <2.0编写).

这是更新的文件(我使用的文件):

softkeyboard.js

cordova.plugins = cordova.plugins || {};

cordova.plugins.SoftKeyBoard = {
show: function (win, fail) {
    return cordova.exec(
        function (args) { if (win !== undefined) { win(args); } },
        function (args) { if (fail !== undefined) { fail(args); } },
        'SoftKeyBoard', 'show', []
    );
},

hide: function (win, fail) {
    return cordova.exec(
        function (args) { if (win !== undefined) { win(args); } },
        function (args) { if (fail !== undefined) { fail(args); } },
        'SoftKeyBoard', 'hide', []
    );
},

isShowing: function (win, fail) {
    return cordova.exec(
        function (args) { if (win !== undefined) { win(args); } },
        function (args) { if (fail !== undefined) { fail(args); } },
        'SoftKeyBoard', 'isShowing', []
    );
}
};
Run Code Online (Sandbox Code Playgroud)

SoftKeyBoard.java

package org.apache.cordova.plugins;

import org.json.JSONArray;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

public class SoftKeyBoard extends Plugin {
public SoftKeyBoard () { }

public void showKeyBoard () {
    InputMethodManager mgr = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.showSoftInput(webView, InputMethodManager.SHOW_IMPLICIT);
    ((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(webView, 0);
}

public void hideKeyBoard() {
    InputMethodManager mgr = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(webView.getWindowToken(), 0);
}

public boolean isKeyBoardShowing() {
    // if more than 100 pixels, its probably a keyboard...
    int heightDiff = webView.getRootView().getHeight() - webView.getHeight();
    return (100 < heightDiff);
}

public PluginResult execute(String action, JSONArray args, String callbackId) {
    if (action.equals("show")) {
        this.showKeyBoard();
        return new PluginResult(PluginResult.Status.OK, "done");
    } else if (action.equals("hide")) {
        this.hideKeyBoard();
        return new PluginResult(PluginResult.Status.OK);
    } else if (action.equals("isShowing")) {
        return new PluginResult(PluginResult.Status.OK, this.isKeyBoardShowing());
    } else {
        return new PluginResult(PluginResult.Status.INVALID_ACTION);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

修改config.xml

还要确保在" res/xml/config.xml "中添加以下行:

<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />
Run Code Online (Sandbox Code Playgroud)