Hide the keyboard when you press Enter in EditText

Asked 2 years ago, Updated 2 years ago, 94 views

What can I do if I want to hide the keyboard when I press EditText Enter?

android edittext

2022-09-21 18:26

1 Answers

edittext.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                //Enter key Action
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow( et_password.getWindowToken(), 0);    //hide keyboard
   return true;
                }
                return false;
            }
        });

this way please


2022-09-21 18:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.