Search code examples
androidandroid-toolbarandroid-hardware-keyboard

How to not show overflow menu in the touch a hardware key


I am using toolbar, add option item in OnCreateOptionsMenu() and set showAsAction="always" so, 3-dot overflow icon does not show. is good work, but show overflow(popup) when i touch the hardware menu key.

I use a hardware key, for other function. How to not show overflow menu in the touch the hardware key?


Solution

  • Found. overflow occurred in KeyUp

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_MENU){
            work(); //handle
            return true;
        }
    
        //not menu key
        return super.onKeyUp(keyCode, event);
    }
    

    works for me