Search code examples
javaandroidkeyboardkeyeventkeycode

KeyEvent code for hiding software keyboard?


When a software keyboard is opened on my virtual device, the back button changes function to hide the keyboard when pressed - it does not stay 'KEYCODE_BACK' like it does whilst the keyboard is hidden.

Is this "hide" button still defined as a KeyEvent or do I need to go a different route in order to run an activity whenever it is pressed?

  • Android Studio 3.0.1

    //setup i was hoping to use, but keycode changes whenever keyboard is shown//
    
    public boolean onKeyDown(int keyCode, KeyEvent event){
            if (keyCode == KeyEvent.KEYCODE_BACK)
            {
                checkEmpty();
            }
            return false;
        }
    

Solution

  • As stated by CommonsWare, "the system does not pass that event [back button while keyboard is displayed] to the activity. It just collapses the input method editor (soft keyboard)."

    So no, it does not trigger a KeyEvent.