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.
This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
You can create class named BaseActivity which will extend AppCompatActivity and put there the code and functionality you want to use in every other Activity . Then in every of your activities, you will extend BaseActivity instead of AppCompatActivity .
You'll want to add android:fitsSystemWindows="true" to the parent layout of the Toolbar to ensure that the height of the activity is calculated correctly. When using the support library, make sure that you are importing android. support. v7.
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's onCreateOptionsMenu
/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's onCreateOptionsMenu
/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.
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