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