Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting splitActionBarWhenNarrow from Java on Android

I'm wondering if it would be possible to tell android to split the ActionBar only when I want it to, but on the same Activity. My use case is that by default, the actions I have on the bar are OK to be collapsed, but on a long click on an item, I enter an "Edit Task" mode, where the action bar is used to provide some shorthands to edit a task. I'd like this "edit mode" to use the split action bar, as it has icon's that are better off to be visible right away, and keep the "not split" action bar for the general view - where it's just "settings" etc.

So the question is, can I set android:uiOptions="splitActionBarWhenNarrow" from the code, instead of hardcode it in the Manifest?

PS: I'm using ActionBar Sherlock.

like image 919
Konrad 'ktoso' Malawski Avatar asked Jul 22 '12 16:07

Konrad 'ktoso' Malawski


1 Answers

The native action bar can be set into split mode by calling getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW).

Window UI options cannot be read after they are set so with ActionBarSherlock you have to call getSherlock().setUiOptions(...). You don't have to call both. ABS will automatically call the above when appropriate.

This must be done before the decor view has been created. The safest place to put this call to ensure that always happens is in your activity onCreate method before you call super.onCreate.

like image 101
Jake Wharton Avatar answered Sep 30 '22 19:09

Jake Wharton