简体   繁体   English

Cordova Ionic Keyboard插件在“Init”上完全禁用

[英]Cordova Ionic Keyboard plugin disable completely on “Init”

I have the following problem, I need to disable the native Keyboard completely. 我有以下问题,我需要完全禁用本机键盘。 The keyboard should only show when I call the show() and hide when I call the close() function (this will be on a Button for the user to toggle the Keyboard). 键盘只应在我调用show()时显示,并在我调用close()函数时隐藏(这将在用户切换键盘的Button上)。 The Keyboard showing on clicking the Field and on Focus needs to be completely disabled. 单击Field和on Focus时显示的键盘需要完全禁用。

On Stackoverflow I found this: InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 在Stackoverflow上我发现了这个:InputMethodManager im =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); im.hideSoftInputFromWindow(editText.getWindowToken(), 0); im.hideSoftInputFromWindow(editText.getWindowToken(),0);

So my thought was In the "Init"(Line 52 in the IonicKeyboard.java) I need to change it. 所以我的想法是在“Init”(IonicKeyboard.java中的第52行)我需要改变它。

if ("init".equals(action)) {
            cordova.getThreadPool().execute(new Runnable() {
                public void run() {

                  //new Logic on init
                  View v = cordova.getActivity().getCurrentFocus();
            ((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);

              DisplayMetrics dm = new DisplayMetrics();
                cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
                final float density = dm.density;

                //http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing
                final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView();
                OnGlobalLayoutListener list = new OnGlobalLayoutListener() {
                    int previousHeightDiff = 0;
                    @Override
                    public void onGlobalLayout() {
                        Rect r = new Rect();
                        //r will be populated with the coordinates of your view that area still visible.
                        rootView.getWindowVisibleDisplayFrame(r);

                        PluginResult result;

                        int heightDiff = rootView.getRootView().getHeight() - r.bottom;
                        int pixelHeightDiff = (int)(heightDiff / density);
                        if (pixelHeightDiff > 100 && pixelHeightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard...
                            String msg = "S" + Integer.toString(pixelHeightDiff);
                            result = new PluginResult(PluginResult.Status.OK, msg);
                            result.setKeepCallback(true);
                            callbackContext.sendPluginResult(result);
                        }
                        else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelHeightDiff ) > 100 ){
                            String msg = "H";
                            result = new PluginResult(PluginResult.Status.OK, msg);
                            result.setKeepCallback(true);
                            callbackContext.sendPluginResult(result);
                        }
                        previousHeightDiff = pixelHeightDiff;
                     }
                };

                rootView.getViewTreeObserver().addOnGlobalLayoutListener(list);


                PluginResult dataResult = new PluginResult(PluginResult.Status.OK);
                dataResult.setKeepCallback(true);
                callbackContext.sendPluginResult(dataResult);
            }
        });
        return true;
    }
    return false;  // Returning false results in a "MethodNotFound" error.
}

Sadly this does not work at all... 可悲的是,这根本不起作用......

I think I have to change the close / show function too but I am not really sure what the correct code is, and I dont know if this change would affect other Keyboard behaviour. 我想我也必须改变关闭/显示功能,但我不确定正确的代码是什么,我不知道这个改变是否会影响其他键盘行为。 (But I basically need Focus without Keyboard) (但我基本上需要没有键盘的焦点)

I also found this Cordova Plugin 我还发现了这个Cordova插件

which looks very promising, but I decided to change this in the Ionic Keyboard Plugin, because I need the same behaviour in Windows too. 看起来非常有前景,但我决定在Ionic Keyboard Plugin中更改它,因为我在Windows中也需要相同的行为。 Very glad if someone could help me out here. 很高兴,如果有人能帮助我在这里。

Regards Christopher 关心克里斯托弗

This can be accomplished by disabling all inputs with ng-disabled and later showing the keyboard with the Ionic Keyboard Plugin . 这可以通过禁用ng-disabled禁用所有输入,然后使用Ionic Keyboard Plugin显示键盘来实现。

If you do not want the inputs to appear differently when disabled, you can override this style with CSS using the :disabled selector. 如果您不希望在禁用时输入显示不同,则可以使用以下命令覆盖此样式:disabled

Hide on load: 加载时隐藏:

<input ng-disabled="hideKeyboard">
hideKeyboard = true;

Show on function: 在功能上显示:

<input ng-disabled="hideKeyboard">
function showKeyboard(){
  hideKeyboard = false;
  cordova.plugins.Keyboard.show();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM