如何隐藏软键盘?

时间:2012-11-23 09:32:26

标签: android

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

我尝试过的事情:

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

<requestFocus />

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

private void hideSoftKeyboard() {

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

    }

4 个答案:

答案 0 :(得分:1)

将此添加到您的清单文件

  android:windowSoftInputMode="stateHidden"

as

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

    </activity>

答案 1 :(得分: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);

答案 2 :(得分: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>

答案 3 :(得分:0)

当你继续使用应用程序manifest.xml时,请写下此代码。

 <activity android:name="yourActName"
        android:configChanges="keyboardHidden" >
    </activity>
相关问题