Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard way to add dividers between action bar items in Android 3.0?

I have a slight problem trying to customise the look of the action bar in my app. I want to be able to have the pixel wide dividers to group action bar items that you see in many of the native apps (e.g. Gmail, Calendar). I found a way to do this by adding a menu item and setting the 'android:actionLayout' attribute to a custom layout for the divider:

<View
  android:background="@color/LightGray"
  android:layout_marginTop="5dip"
  android:layout_marginBottom="5dip"
  android:layout_width="1dip"
  android:layout_height="fill_parent" />

This works nicely, but the issue is it counts as a menu item and the action bar seems to limit the number of menu items to 4 - any others get pushed into the overflow menu.

So I guess what I'm asking is whether there is a standard way to add item dividers without having to use a menu item with a custom view, and in a way that doesn't count towards the limit for action bar items?

Thanks in advance!

like image 232
kingraam Avatar asked May 06 '11 10:05

kingraam


People also ask

How do you add action items to the action bar in Android?

All action buttons and other items available in the action overflow are defined in an XML menu resource. 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 the purpose of 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.

What is action bar icon?

In Android applications, ActionBar is the element present at the top of the activity screen. It is a salient feature of a mobile application that has a consistent presence over all its activities.


2 Answers

I wouldn't try and force dividers into places that the system does not add them automatically as it will make your app inconsistent with the platform. The default behavior is:

  • Divider between overflow and others.
  • Divider between text and another item where it would disambiguate which item the text belongs to.
like image 192
crafty Avatar answered Sep 17 '22 22:09

crafty


I couldn't find a standard way, but the way I did it was to use the android:actionLayout property for the menu item, and I put the divider in there.

like image 40
Christopher Perry Avatar answered Sep 19 '22 22:09

Christopher Perry