Q:

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.

A:

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.

A:

Take a look at the ActionBarSherlockSamples, SplitActionModes.java. In this example, when the button 'Start' is pressed, a split action bar shows up in the bottom of the screen:
Call this to show the split actionbar:
mMode = startActionMode(new AnActionModeOfEpicProportions());

mMode is type of ActionMode and you need to call 'finish()' on it when you want the action bar to go away.
AnActionModeOfEpicPropotions is an implementation of ActionMode.Callback:
private final class AnActionModeOfEpicProportions implements ActionMode.Callback {
    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        // add your menu here...
    }

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        // handles your action menu clicked event
        return true;
    }
}

