Actionbar Menuitem Divider

ActionBar MenuItem Divider

I found an answer by myself with help of http://android-developers.blogspot.in/2011/04/customizing-action-bar.html However, this does not completely solve my problem. It adds a divider for Title, and also one for the home Icon. There are also left and right separators. That too is adjustable.

I added android:selectableItemBackground to my theme.

<item name="android:selectableItemBackground">@drawable/action_bar_item_selector</item>

action_bar_item_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:drawable="@drawable/actionbar_compat_separator"></item>

<item android:left="1dp" android:drawable="@drawable/actionbar_compat_item"></item>

</layer-list>

actionbar_compat_separator - is my seperator drawable

and actionbar_compat_item is my selector for action bar item.

EDITED

I have found a better solution to my problem. It works well.

<item name="android:actionButtonStyle">@style/ActionButton</item> to my Theme

<style name="ActionButton" parent="android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">@drawable/action_bar_item_selector</item>
</style>

ActionBar Divider Styling

the attribute you are looking for is:

<style name="Theme.Example" parent="Theme.Sherlock">
<item name="actionBarDivider">@drawable/small_detail_divider</item>
....
<item name="android:actionBarDivider">@drawable/small_detail_divider</item>
...
</style>

Just to give you some more info.

The split ActionBar should be set with:

<style name="Theme.Example" parent="Theme.Sherlock">
<item name="actionBarSplitStyle">@style/Widget.Styled.ActionBarSplit</item>
<item name="android:actionBarSplitStyle">@style/Widget.Styled.ActionBarSplit</item>
...

Then provide your custom style for the split action bar..

Thrid question: Adding in order:

When you add the menu item pragmatically use: Menu

menu.add (0, R.id.menu_new_ab_item, 0, "Item");

The order determines how you order your menu items.

You can be more specific in your menu.xml files android:orderInCategory="1..n" can be any int. I normally start at 10 or so, so I can inflate items in-front of the standard items.

How can I remove divider before actionbar menuItem which only have text on it?

The android:actionBarDivider attribute belongs to the theme, not to the action bar style. You can remove the divider like this:

<style name="AppTheme" parent="Theme.Sherlock">
<item name="actionBarDivider">@null</item>
<item name="android:actionBarDivider">@null</item>
</style>

ActionBarSherlock Custom MenuItem Divider

  1. Modifying that method will only affect pre-ICS phones so you will still get the natural divider behavior on ICS+. This means that your app will look differently based on what version of Android is running it.

  2. You can change the divider with the actionBarDivider theme attribute.

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

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.


Related Topics



Leave a reply



Submit