35

I have an application with an EditText element on the main view. This means that when my application is loaded the soft keyboard appears per default.

I would like to be able to hide the keyboard on load, so it does not show until i tap on the EditText view.

How do i manage this?

inazaruk
  • 73,337
  • 23
  • 185
  • 156
Esben Andersen
  • 781
  • 2
  • 8
  • 17

3 Answers3

87

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.

inazaruk
  • 73,337
  • 23
  • 185
  • 156
  • Maybe I don't know english that well , where do you see in the explanation that _shown only when user clicks the edit box_ ? The docs says :"_The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity._". Don't get me wrong . your explanation is fully clear. But the docs isnt. – Royi Namir Feb 27 '18 at 13:20
29

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"
...
/>
Devrath
  • 39,949
  • 51
  • 178
  • 266
neteinstein
  • 17,327
  • 11
  • 90
  • 120
  • 3
    The accepted answer didn't work for me, I already had stateHidden set. This suggestion works. I applied it to the XML layout instead: android:focusable="true" and android:focusableInTouchMode="true" on a parent view group. – James Wald Jan 05 '12 at 22:49
5
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);
Stephen C
  • 669,072
  • 92
  • 771
  • 1,162
John Cooper
  • 6,915
  • 27
  • 75
  • 99