如何在cordova应用程序中工作时禁用Android软键盘

时间:2021-05-02 20:17:49

I have cordova application which loading the html pages from web. Now these web pages have input fields, so when click on these input fields android default keyboard appear. I dont want to use this keyboard as already have customize keyboard as popup in side application. What i try: add following configuration inside my activity in androidManifest.xml

我有cordova应用程序从web加载html页面。现在这些网页都有输入字段,所以当点击这些输入字段时,会出现Android默认键盘。我不想使用这个键盘,因为已经有自定义键盘作为侧面应用程序中的弹出窗口。我尝试了:在androidManifest.xml中的活动中添加以下配置

  <activity
        android:name=".MainActivity"
        android:screenOrientation="sensorLandscape"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustResize|stateHidden"
       android:configChanges="keyboardHidden|orientation|screenSize">

But nothing can stop appearing this default keyboard. Can someone suggest me how to disable keyboard for my application only.

但没有什么可以停止出现这个默认键盘。有人可以建议我如何为我的应用程序禁用键盘。

2 个解决方案

#1


0  

You need to add this line in Manifest.

您需要在Manifest中添加此行。

 <activity android:name=".MainActivity" 
              android:windowSoftInputMode="stateHidden" />

Look at this answer.

看看这个答案。

#2


0  

Not a good way but works:

不是一个好方法,但有效:

 @Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    super.dispatchTouchEvent(ev);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager inputManager = (InputMethodManager)
                    getSystemService(Context.INPUT_METHOD_SERVICE);

            inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }, 100);
    return true;
}

#1


0  

You need to add this line in Manifest.

您需要在Manifest中添加此行。

 <activity android:name=".MainActivity" 
              android:windowSoftInputMode="stateHidden" />

Look at this answer.

看看这个答案。

#2


0  

Not a good way but works:

不是一个好方法,但有效:

 @Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    super.dispatchTouchEvent(ev);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager inputManager = (InputMethodManager)
                    getSystemService(Context.INPUT_METHOD_SERVICE);

            inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }, 100);
    return true;
}