I have been trying to hide the keyboard when user enters an activity,i checked and tried various ways and method but the one I lost see is hide keyboard on button click. I don't want the keyboard to hide on only button, I want it to be hidden when the activity starts. I also tried to put the code in an onCreate method but still the same.another on I saw on Android arsenal was to click on any part of the screen to hide the keyboard was nice but still I still prefer the keyboard hidden when the activity starts, please is there any way hiding the keyboard when the activity starts?
-
So you have EditTexts in the Activity I'm guessing? – TheWanderer Nov 15 '18 at 02:13
-
In your manifest add ths line inside the
tag add this: **android:windowSoftInputMode="stateHidden"** – Sayok Majumder Nov 15 '18 at 09:31
2 Answers
Your solution is here
There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText
or focusable control in your Activity
. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.
<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
Almost unbelievably, it appears to do nothing to prevent the keyboard from opening when you touch the control (unless focusable="false"
and/or focusableInTouchMode="false"
are assigned to the control). Apparently, the windowSoftInputMode setting applies only to automatic focus events, not to focus events triggered from touch events.
Therefore, stateAlwaysHidden
is VERY poorly named indeed. It should perhaps be called ignoreInitialFocus
instead.

- 3,255
- 27
- 43
Write this line on oncreate method
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

- 284
- 5
- 5