Alex Rivera | Logout

ActionBar MenuItem Divider

Asked 2012-07-05T06:30:23.343
14

Is there a way to show Divider between the Menu Items in ActionBar for HoneyComb+.

Some post says that the Divider will be shown only when the menu items has android:showAsAction="withText".

I want to show only the Icon not the Text.

I successfully shown Divider for Pre-HoneyComb by implementing a Action Bar Compatibility.

I dont want to use ActionBarSherlock as given in this post Android actionbar sherlok doesn't show divider because it will be time to change from Action Bar Compatibility to ActionBarSherlock in my all Projects.

When i saw the Android Source i found that Divider will be show only when it has text as shown below (from ActionMenuItemView)

public boolean needsDividerBefore() {
    return hasText() && mItemData.getIcon() == null;
}

public boolean needsDividerAfter() {
    return hasText();
}

Is there a way that I can give my Implementation for ActionMenuItemView for ActionBar where needsDividerBefore() will always give true

Edit
Report

1 Answer

7

You can override existing theme with custom styles, for e.g.

<style name="CustomTheme" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/action_bar_background</item>
    <item name="android:showDividers">beginning</item>
    <item name="android:divider">@color/action_bar_divider</item>
</style>
answered 2012-09-03T11:44:41.723

Your Answer