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?
Here pass HIDE_IMPLICIT_ONLY at the position of showFlag and 0 at the position of hiddenFlag . It will forcefully close soft Keyboard.
and put the following code in the onTouch method. InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow(getCurrentFocus(). getWindowToken(), 0);
Hiding the Soft Keyboard Programmatically You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.
Show software keyboard for numeric input EditText and hide on other input EditText. Android has no property API to disable the software keyboard from coming up, when a user touches an EditText.
Close EditText Smart pad keyboard on button click through coding. After clicking on EditText it will automatically open a soft keyboard also known as smart pad to enter alphabetic, numeric, symbols values inside edittext so user can use them any where.
However, there’s no same support for WebView yet! Check out the result below, the focus retains in EditText, and selection together with context menu all work, but however hard you tried clicking, the soft keyboard just won’t show up. This is great! Now you can programmatically to make the view of custom keyboard visible.
To show soft keyboard, you have to write following code in long key press event of menu button editText.setInputType (InputType.TYPE_CLASS_TEXT); editText.requestFocus (); InputMethodManager mgr = (InputMethodManager) getSystemService (Context.INPUT_METHOD_SERVICE); mgr.showSoftInput (editText, InputMethodManager.SHOW_FORCED);
This will help you
editText.setInputType(InputType.TYPE_NULL);
Edit:
To show soft keyboard, you have to write following code in long key press event of menu button
editText.setInputType(InputType.TYPE_CLASS_TEXT); editText.requestFocus(); InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
You need to add the following attribute for the Activity
in your AndroidManifest.xml
.
<activity ... android:windowSoftInputMode="stateHidden|adjustResize" ... />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With