user1026605
user1026605

Reputation: 1430

How to dynamically replace/hide items in an ActionBar

I'm using an ActionBar that displays some MenuItems icon. What I need, is to be able to replace or Hide some MenuItems when the activity opens. My problem is that I can't find a way to get a MenuItem reference outside the onCreateOptionsMenu() method... Any idea on how to do that ?

Upvotes: 0

Views: 350

Answers (1)

input
input

Reputation: 7519

You can use onPrepareOptionsMenu (Menu menu) to show/hide menu items in the activity:

@Override
public boolean onPrepareOptionsMenu (Menu menu) {
    menu.getItem(0).setVisible(false);
    return super.onPrepareOptionsMenu(menu);
}

Upvotes: 1

Related Questions