【问题标题】:Disabling keyboard for the entire app (Android)禁用整个应用程序的键盘 (Android)
【发布时间】:2015-12-29 11:13:05
【问题描述】:

我正在使用 webView(全屏),它在需要时有自己的键盘。 我想禁用每次弹出的android键盘。

我试过用hideSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0); 来做这件事,但它不起作用。 android:windowSoftInputMode="stateAlwaysHidden"也没有
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

【问题讨论】:

标签: android webview keyboard


【解决方案1】:

您必须为清单文件中的每个活动添加android:windowSoftInputMode="stateAlwaysHidden"。像这个例子

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

【讨论】:

  • 正如我在帖子中提到的 - 我已经尝试过了。不幸的是,由于某种原因它没有帮助
【解决方案2】:

使用下面的函数并在 webview 的 onTouch() 中调用它:

public static void hideSoftKeyboard(Activity activity) {
    try {
        InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

【讨论】:

  • 但我没有 EditText 。所有的“编辑文本”都是 webview 的。
【解决方案3】:
 if (mActivity.getCurrentFocus() != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) mActivity.getSystemService(mActivity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(), 0);
        }

【讨论】:

    【解决方案4】:

    试试这个:

    <activity          
                android:configChanges="keyboard|keyboardHidden"
                android:windowSoftInputMode="stateAlwaysHidden">
    

    【讨论】:

    • 很遗憾没有变化:/
    【解决方案5】:

    layout.xml 的主(父)布局中添加以下代码

    android:descendantFocusability="blocksDescendants"
    

    希望它会奏效。并在您的 webview 中设置以下属性

    android:focusable="false" 
    android:focusableInTouchMode="true"
    
    
    
    See it:
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:descendantFocusability="blocksDescendants"
        android:paddingBottom="@dimen/activity_vertical_margin"     tools:context=".MainActivityFragment">
    
        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:focusable="false"
            android:focusableInTouchMode="false">
        </WebView>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 2017-04-22
      相关资源
      最近更新 更多