Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide keyboard after typing in EditText in android?

I have a EditText and button aligned to parent's bottom.

When I enter text in it and press the button to save data, the virtual keyboard does not disappear.

Can any one guide me how to hide the keyboard?

like image 739
UMAR-MOBITSOLUTIONS Avatar asked Feb 26 '10 15:02

UMAR-MOBITSOLUTIONS


People also ask

How do you hide the keyboard when typing?

Tap the back button on your Android. It's the left-pointing arrow button at the bottom of the screen, either at the bottom-left or bottom-right corner. The keyboard is now hidden. The back button may be a physical button or on the touch screen. To bring the keyboard back into view, tap the typing area.

How do I hide the soft keyboard on Android after clicking outside EditText?

and put the following code in the onTouch method. InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow(getCurrentFocus(). getWindowToken(), 0);

How do I hide the keyboard on my Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases, you will want to pass in InputMethodManager.

What is Imeoption Android?

android:imeOptions="actionSend" /> You can then listen for presses on the action button by defining a TextView.OnEditorActionListener for the EditText element. In your listener, respond to the appropriate IME action ID defined in the EditorInfo class, such as IME_ACTION_SEND . For example: Kotlin Java.


2 Answers

You might also want to define the imeOptions within the EditText. This way, the keyboard will go away once you press on Done:

<EditText     android:id="@+id/editText1"     android:inputType="text"     android:imeOptions="actionDone"/> 
like image 188
angelrh Avatar answered Sep 21 '22 08:09

angelrh


This should work.

InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);  inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);  

Just make sure that this.getCurrentFocus() does not return null, which it would if nothing has focus.

like image 37
Ryan Alford Avatar answered Sep 21 '22 08:09

Ryan Alford