how to hide an item in the menu

Asked

Viewed 154 times

2

I created a menu with buttons to save, back and add, and would like when you click add it to be hidden or disabled. I tried to use MenuItem item = menu.findItem(R.id.my_item); in which I saw in this topical but gets red striped under the line and the message unreachable statement is displayed when I hover over it. any hint of how to hide the item in the menu ?

1 answer

3


All you have to do is instantiate the menu:

Menu menu = navView.getMenu();

and set the attribute visible

menu.findItem(R.id.my_item).setVisible(false);

Already the mistake unreachable statement gives itself to some logic error of its code, which means that the statement is inaccessible.

Maybe you’re giving one return in the line above, for example.

  • navView is not recognized

  • navView is the name of my attribute NavigationView. Just change the name you’re using

Browser other questions tagged

You are not signed in. Login or sign up in order to post.