How to force use of overflow menu on devices with menu button

前端 未结 11 631
谎友^
谎友^ 2020-11-22 14:04

I\'d like to have all of the menu items that don\'t fit into the ActionBar go into the overflow menu (the one that is reached from the Action Bar not the menu button) ev

11条回答
  •  一生所求
    2020-11-22 14:32

    For anyone using the new Toolbar:

    private Toolbar mToolbar;
    
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
    
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
    
        ...
    }
    
    
    @Override
    public boolean onKeyUp(int keycode, KeyEvent e) {
        switch(keycode) {
            case KeyEvent.KEYCODE_MENU:
                mToolbar.showOverflowMenu();
                return true;
            }
    
        return super.onKeyUp(keycode, e);
    }
    

提交回复
热议问题