I have an Activity with ActionBar and tab navigation. I am using the split mode, so the tabs are at the top and actions are in the bottom bar. How can I dynamically change the bottom actions? I need this because every tab has different actions.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
ActionMode.invalidate() did the trick. It caused the
onPrepareActionMode()
to be invoked again.Activity#invalidateOptionsMenu()
did not cause theonPrepareActionMode()
to be invoked when using list items with multi-select.Activity.invalidateOptionsMenu()
requires API Level 11. Use the Support library version of it supportInvalidateOptionsMenu().Since the actions are populated by the activity's options menu you can use
Activity#invalidateOptionsMenu()
. This will dump the current menu and call your activity'sonCreateOptionsMenu
/onPrepareOptionsMenu
methods again to rebuild it.If you're using action bar tabs to change your fragment configuration there's a better way. Have each fragment manage its own portion of the menu. These fragments should call
setHasOptionsMenu(true)
. When fragments that have options menu items are added or removed the system will automatically invalidate the options menu and call to each fragment'sonCreateOptionsMenu
/onPrepareOptionsMenu
methods in addition to the activity's. This way each fragment can manage its own items and you don't need to worry about performing menu switching by hand.Activity.invalidateOptionsMenu() requires API Level 11. There is a simpler solution which is backwards compatible:
Add the MenuItem to the Menu initially but set its visibility to false. Set visibility to true when desired, using MenuItem.setVisible()