Search code examples
androidandroid-softkeyboard

Soft Keyboard hide on backpress


I need to identify the event of back press which hide the softkeyboard
I have tested by override following methods

  1. onKeydown
  2. onBackPressed
  3. onConfigurationChanged
  4. dispatchKeyEvent

But the controller is not reaching there


Solution

  • Use dispatchKeyEventPreIme in subclassed EditText view:

    @Override
    public boolean dispatchKeyEventPreIme(KeyEvent event) {
        if(KeyEvent.KEYCODE_BACK == event.getKeyCode()) {
           //do what you need here
        }
        return super.dispatchKeyEventPreIme(event);
    }