Hide soft keyboard on application load

感情迁移 提交于 2019-11-29 21:24:49
neteinstein

You can do something easier. Add this to the LinearLayout (or any other layout that is the root):

<LinearLayout
...
android:focusable="true"
android:focusableInTouchMode="true"
...
/>

In your AndroidManifest.xml:

<activity android:name="com.your.package.ActivityName"
          android:windowSoftInputMode="stateHidden"  />

More details about windowSoftInputMode can be found here.

This setting will hide soft keyboard when user enters new Activity (even if EditText control gains the focus). Soft keyboard will be shown only when user clicks the edit box control.

John Cooper
InputMethodManager imm = 
    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

This will hide in all situations (even when the EditView has focus):

 EditText editView = (EditText) findViewById(R.id.editTextConvertValue);
 editView.setInputType(InputType.TYPE_NULL);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!