How to control ActionBar split programmatically?
Asked Answered
V

5

23

The android ActionBar may split into a top and bottom bars if activity's parameter "uiOptions" is set to "splitActionBarWhenNarrow", note this parameter is only valid in ICS.

Honeycomb has introduced a new approach to multi-select list items using action bar. When a item is under press & hold the list becomes into a multi-selection mode and the actionbar bar may be used to accomplish some actions. The actionbar setup is inherited from the list activity, i.e., if the activity has a split action bar the multi-selection will have too, and if the activity has only the top bar, so, the multi-selection will be compliant with that.

The question is, is it possible to have only a top action bar in the activity and when the list turns into multi-selection mode programmatically split the actionbar?

Thanks!

Viera answered 25/11, 2011 at 16:28 Comment(3)
I too would LOVE for it to have this functionality.Dilorenzo
Well, you always can do a custom bottom bar, which would be above if one situation and below, if - like you said - list is shownProvenience
please visit links below to check how to do itProvenience
P
26

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.

Pease answered 26/11, 2011 at 18:52 Comment(2)
Yeah, but my users seem to be having a hard time finding the contextual actions during the action mode as most of them spill into the overflow menu because of the "X Selected" text informing them of how many items they have currently selected.Dilorenzo
If that particular action mode is a significant part of your UI and presents many options, you might consider using the split bar full-time for that activity.Pease
N
2

I don't believe so. I do not see anything in Activity that would serve as a setter counterpart to android:uiOptions.

Nixon answered 25/11, 2011 at 17:21 Comment(0)
A
1

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.

Amelioration answered 14/11, 2014 at 6:56 Comment(0)
V
0

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. :)

Vallecula answered 6/2, 2014 at 20:22 Comment(0)
S
0

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

Synovia answered 3/3, 2015 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.