0

I am using ActionBarSherlock.

I want to change which ActionBar MenuItems are visible depending on the state of my Activity. (For instance depending on which tab is selected.)

How can I do this?

flup
  • 26,937
  • 7
  • 52
  • 74

2 Answers2

1

You can get the ActionMenu within the onCreateOptionsMenu method and store it in your activity and change any item visibility at any time...

ChristopheCVB
  • 7,269
  • 1
  • 29
  • 54
  • Toggling the visibility in onCreateOptionsMenu was insufficient for me. I needed to put the code into the "onPrepareOptionsMenu" so that the visibility could keep up to date with the current state of my app. See [onCreateOptionsMenu vs onPrepareOptionsMenu](http://stackoverflow.com/questions/14043631/what-is-the-difference-between-oncreateoptionsmenumenu-menu-and-onprepareoptio). Maybe this is different b/c you use ActionBarSherlock, but I do not. – dannyhan12 Feb 23 '14 at 15:21
0

You can add all items at the same menu and set it visible or not visible just using:

menu.findItem(R.id.your_item).setVisible(true/false);

in onPrepareOptionsMenu

Vurtne
  • 45
  • 1
  • 6