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,
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
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?
My test result:
with: editText.setInputType(InputType.TYPE_NULL);
the softkeyboard disappear, but the cursor will also disappear.
with: editText.setShowSoftInputOnFocus(false)
It works as expected.
The soft keyboard kept rising even though I set
EditorInfo.TYPE_NULL
to the view. None of the answers worked for me, except the idea I got from nik431's answer:Simply Use
EditText.setFocusable(false);
in activityor use in xml
I sometimes use a bit of a trick to do just that. I put an invisible focus holder somewhere on the top of the layout. It would be e.g. like this
with this style
and then in onResume I would call
That works nicely for me from 1.6 up to 4.x
Let's try to set the below properties in your xml for
EditText
if you want to hide the softkeypad at launching activity please go through this link