How can I alter a MenuItem on the Options Menu on Android?

后端 未结 6 1300
耶瑟儿~
耶瑟儿~ 2020-12-08 03:59

I have an Options Menu on my Activity with an MenuItem \"Start\". When this MenuItem is selected I would like to alter the Menu so it

6条回答
  •  北海茫月
    2020-12-08 04:31

    For this type of operation I usually choose not to alter the menu items, but just hide the ones you don't need:

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        menu.findItem(R.id.start).setVisible(!isStarted);
        menu.findItem(R.id.stop).setVisible(isStarted);
        return true;
    }
    

提交回复
热议问题