How to disable a particular option from optionmenu across all the tabs in android?
I am developing an applicati开发者_运维问答on which consists of four tabs. Its also having six optionmenu which is common to all the four tabs and I need to disable one of the option menu depending on the current state of the application. Is there any way to disable particular option from the optionmenu across all the tabs??
To disable a menu item, you can override onPrepareOptionsMenu
in your activity:
public boolean onPrepareOptionsMenu(Menu menu) {
// To disable the item
menu.findItem(R.id.the_menu_id).setEnabled(false);
// To make the item invisible
menu.findItem(R.id.the_menu_id).setVisibility(false);
}
If your tabs are composed of multiple views, then you only need to override the method in one place. If your tabs are composed of multiple activities, then you'll need to override the method in each of your activities and choose which items to display based on your application's state.
精彩评论