How to hide Soft Keyboard when activity starts

Aju picture Aju · Sep 24, 2013 · Viewed 208.7k times · Source

I have an Edittext with android:windowSoftInputMode="stateVisible" in Manifest. Now the keyboard will be shown when I start the activity. How to hide it? I cannot use android:windowSoftInputMode="stateHidden because when keyboard is visible then minimize the app and resume it the keyboard should be visible. I tried with

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

but it did not work.

Answer

Neenu picture Neenu · Sep 24, 2013

In the AndroidManifest.xml:

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

or try

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)‌​;

Please check this also