How to disable menu button and the action bar still remains there

前端 未结 1 475
野的像风
野的像风 2021-01-06 11:18

I have a problem in disabling menu button , I dont want the menu button to be enable , I disable is by returning false in onPrepareOptionsMenu func

相关标签:
1条回答
  • 2021-01-06 12:12

    Hardware menu button is not controlled by onPrepareOptionsMenu(). Generally speaking, it is not good practice to change the behavior of hardware buttons because users expect it to behave a certain way (which I believe is to expand the overflow menu).

    If you absolutely have to disable it, you could listen for it to be pressed in our Activities like this:

    public boolean dispatchKeyEvent(KeyEvent event) {
        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        if (keycode == KeyEvent.KEYCODE_MENU && action == KeyEvent.ACTION_UP) {
            return true; // consume the key press
        }
        return super.dispatchKeyEvent(event);
    }
    
    0 讨论(0)
提交回复
热议问题