Home » Android » android – After type in EditText, how to make keyboard disappear

android – After type in EditText, how to make keyboard disappear

Posted by: admin June 15, 2020 Leave a comment


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 click at EditText, it has a keyboard appear on the frame. I want to know after Enter.
How to make keyboard out from frame except click Back.

enter image description here

Thank you

How to&Answers:

Try the following

For Activity:

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

In case of Fragment :

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


give the EditText box you have the attribute android:imeOptions="actionDone"
this will change the Enter button to a Done button that will close the keyboard.


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



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


This will automatically force the text to be on a single line and therefore when we click Enter, the keyboard disappears.