Reputation: 590
I have an app with an action bar and menu resource folder with an menu_main.xml file in it, I suppose I'm right in assuming that each resource file should have an activity?
If not is there a way to dynamically change the android:visible="false" to android:visible="true"? Or am I going about it the wrong way?
Upvotes: 1
Views: 195
Reputation: 36449
Menus are for Activities, not layouts.
To answer your question, there is a way to dynamically change the visibility. In your onCreateOptionsMenu (Menu menu)
method, you can set individual menu components to be visible/invisible.
Eg.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
menu.findItem(R.id.myMenuItem1).setVisible(false);
}
However, I would stick with making a separate menu xml per Activity - it's small (it is just text after all), and it helps make sure that you're not mixing stuff up.
Upvotes: 1