ScubaSteve ScubaSteve - 1 year ago 191
Android Question

How to hide Android soft keyboard on EditText

I have an Activity with some EditText fields and some buttons as a convenience for what normally would be used to populate those fields. However when we the user touches one of the EditText fields the Android soft keyboard automatically appears. I want it to remain hidden by default, unless the user long presses the menu button. I have search for a solution to this and found several answers, but so far I can't get them to work.

I have tried the following:

1 - In the onCreate method,


2 - Also in the onCreate method,

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);

3 - and fIn the Manifest file,

<activity android:name=".activityName" android:windowSoftInputMode="stateAlwaysHidden"/>

None of these methods work. Whenever the user clicks on the EditText field, the soft keyboard appears. I only want the soft keyboard to appear if the user explicitly shows it by long pressing the menu key.

Why isn't this working?

Answer Source

This will help you



To show soft keyboard, you have to write following code in long key press event of menu button

            InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download