The android ActionBar
may split into a top and bottom bars if activity\'s parameter \"uiOptions
\" is set to \"splitActionBarWhenNarrow
The AppCompat package now offers the Toolbar widget that allows you to put an actionbar anywhere you want in your layout and modify it like any other view..
Please see the full documentation here and a guide here.
Can you try to set getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW)
in the Activity
you want the ActionBar
to show as split right before its onCreate()
, then hide it using getActionBar.hide()
and on the list action you are referring to make it pop-up back using getActionBar.show()
.
I tried (not with the support libraries though) showing ActionBar
in one Activity
and Split in another using the above and was able to hide and show the split on button clicks. Hope this helps. Let me know in case it did or even didn't. Happy coding. :)
I don't believe so. I do not see anything in Activity
that would serve as a setter counterpart to android:uiOptions
.
No, you cannot switch between split and non-split action bars on the fly.
The setter counterpart to android:uiOptions
is on Window
, not Activity
. Window#setUiOptions is the method and the flag to use is ActivityInfo#UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW.
However this isn't going to do what you want. Split action bar when narrow must be specified as the window is first configured before the window decor is initialized. In other words, once the window has been displayed (or even once you've called setContentView
) it's too late to change it.
This was a conscious decision by the Android UX team. Action modes (including selection modes) are meant to mirror the configuration of the action bar on the current activity. This gives the user a single place to look for currently valid actions within the same activity.
You can use two Toolbars. Have a look at these questions:
AppCompat v7:21 Split Action Bar Broken?
How to center action menu on toolbar