I have a menu item and I want to change its visibility programmatically. The menu is this
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);