0

我有一个显示视图的活动。该视图由各种小部件组成,其中之一是多行 EditText。当视图膨胀时,软键盘出现我如何禁用它?

我尝试过的事情:

从 EditText 中的布局中删除以下内容。

<requestFocus />

.

创建以下方法,然后从 oncreate 方法调用它(分辨率为 EditText)。

private void hideSoftKeyboard() {

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(resolution.getWindowToken(), 0);

    }
4

4 回答 4

1

将此添加到您的清单文件中

  android:windowSoftInputMode="stateHidden"

作为

<activity android:name=".youractivity"
              android:windowSoftInputMode="stateHidden"

    </activity>
于 2012-11-23T09:33:54.900 回答
0

隐藏它:

editText.setInputType(InputType.TYPE_NULL);

当您需要展示它时,请使用:

editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.requestFocus();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
于 2012-11-23T09:34:58.910 回答
0
android:descendantFocusability="beforeDescendants"
 android:focusableInTouchMode="true"

在顶视图中添加这两行

前任:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:descendantFocusability="beforeDescendants" <-----
    android:focusableInTouchMode="true" > <-----
    ....
    EditText
    .....
    </RelativeLayout>
于 2012-11-23T09:37:09.813 回答
0

当您继续使用您的应用程序 manifest.xml 时,然后编写此代码。

 <activity android:name="yourActName"
        android:configChanges="keyboardHidden" >
    </activity>
于 2012-11-23T09:58:10.897 回答