how to hide menu items in android

Solutions on MaxInterview for how to hide menu items in android by the best coders in the world

showing results for - "how to hide menu items in android"
Helene
26 Mar 2018
1//anywhere in your code
2...
3mState = HIDE_MENU; // setting state
4invalidateOptionsMenu(); // now onCreateOptionsMenu(...) is called again
5...
6
7@Override
8public boolean onCreateOptionsMenu(Menu menu)
9{
10    // inflate menu from xml
11    MenuInflater inflater = getSupportMenuInflater();
12    inflater.inflate(R.menu.settings, menu);
13
14    if (mState == HIDE_MENU)
15    {
16        for (int i = 0; i < menu.size(); i++)
17            menu.getItem(i).setVisible(false);
18    }
19}
20