After entering type EditText, how to make the keyboard disappear

From the android tutorial:

pass_text.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); } 

when you click on EditText, the keyboard is displayed on it. I want to know after Enter. How to make the keyboard out of the frame, except to press "Back".

enter image description here

thanks

+7
source share
4 answers

Try to execute

For activity:

 InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(curEditText.getWindowToken(), 0); 

In the case of a fragment:

 InputMethodManager mgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); 
+24
source

enter the EditText field, you have the android:imeOptions="actionDone" attribute android:imeOptions="actionDone" this will change the "Enter" button to the "Finish" button, which will close the keyboard.

+14
source

The working approach to get rid of the soft keyboard is to disable and then enable the TextEdit field in the Return-key event, button click event, or something else. For example:

 .... pass_text.setEnabled(false); pass_text.setEnabled(true); .... 
+1
source

I think we can just add this attribute to our EditText:

Android: inputType = "text"

This will automatically force the text to be on the same line, so when we press Enter, the keyboard disappears.

0
source

All Articles