Since actions are populated with an action options menu, you can use Activity#invalidateOptionsMenu() . This will unload the current menu and call the onCreateOptionsMenu / onPrepareOptionsMenu methods onCreateOptionsMenu to rebuild it.
If you use the action bar tabs to better change the fragment configuration. Each fragment controls its part of the menu. These fragments should call setHasOptionsMenu(true) . When fragments with options menu items are added or removed, the system automatically cancels the options menu and calls all onCreateOptionsMenu / onPrepareOptionsMenu in addition to the action. Thus, each fragment can manage its own elements, and you do not need to worry about manually switching the menu.
adamp Nov 26 '11 at 18:40 2011-11-26 18:40
source share