changing menu item programmatically is not working in android

后端 未结 2 1254
面向向阳花
面向向阳花 2021-01-24 15:55

I have a menu item and I want to change its visibility programmatically. The menu is this




        
2条回答
  •  天命终不由人
    2021-01-24 16:19

    The way to access the menu through the toolbar, and no need to dedicate variable:

    MenuItem menuItem = ((Toolbar)findViewById(R.id.toolbar)).getMenu().findItem(R.id.pencil);
    menuItem.setVisible(true);
    

提交回复
热议问题