Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add actions to the top part of a split ActionBar

If an Android ActionBar is split into a top and a bottom portion using android:uiOptions="splitActionBarWhenNarrow" in the Manifext.xml, is there a way to force some of the actions to be displayed in the top portion instead of having them all at the bottom?

like image 602
Marcus Wolschon Avatar asked Jan 31 '12 08:01

Marcus Wolschon


People also ask

How do I add an action bar?

To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.

What is split action bar?

You can adapt to such changes by using split action bars, which allow you to distribute action bar content across multiple bars located below the main action bar or at the bottom of the screen. Split action bar showing action buttons at the bottom of the screen in vertical orientation.

What is the action bar in Android?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button. In general an ActionBar consists of the following four components: App Icon: App branding logo or icon will be displayed here.


2 Answers

There's no standard way of doing this. That said, the Action Bar custom view will appear in the upper bar, so you can just use that. You will lose some of the extras (toasts on long press), so you'll have to implement them yourself. That said, of you're using ActionBarSherlock, all the layouts and styles for a normal button are there, so you can just use those.

like image 99
Delyan Avatar answered Oct 26 '22 20:10

Delyan


Yes! You can continue to use android:uiOptions="splitActionBarWhenNarrow" in your Manifest.xml.

You just also need to set:

// set the actionbar to use the custom view
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

//set the custom view to use
getActionBar().setCustomView(R.layout.custom_action_bar_top);

Where R.layout.custom_action_bar_top would be a view that has all the buttons you wish to appear in the top action bar.

All the menu items that you want at the bottom, should be added as usual in the onCreateOptionsMenu method of your activity.

like image 43
Dylan Watson Avatar answered Oct 26 '22 20:10

Dylan Watson