Trying to hide and show menu items on action bar

后端 未结 4 991
灰色年华
灰色年华 2021-02-05 19:26

I have looked through the questions on stack overflow and can\'t find the solution.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater i         


        
4条回答
  •  悲哀的现实
    2021-02-05 20:08

    Its not enough to change the isDown variable. You have to call the setVisible() method every time you want to change the visibility. That method does more than just setting a boolean value, so just changing a boolean value will not do.

    After changing the isDown value to false, you need to call invalidateOptionsMenu() which will re-launch the menu by calling onPrepareOptionsMenu() again.

    Try this code for making the menu items unvisible:

    ...
    isdown = false;
    invalidateOptionsMenu();
    ...
    

提交回复
热议问题