Is there a way to dynamically disable , hide, add/remove menu items in ActionBar ? For example, an action is disabled until user fills a valid phone number in an activity.
I didn't find any useful methods in ActionBar API, the only way seems to be using a custom View in ActionBar.
To tell ActionBar to refresh its menu items: invalidateOptionsMenu()
then to enable/disable Menu Items:
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item= menu.findItem(R.id.men_1);
//depending on your conditions, either enable/disable
item.setEnabled(false);
super.onPrepareOptionsMenu(menu);
return true;
}
and to hide the action bar you have:
getActionBar().hide();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With