Showing dividers between menu items in android act

2019-09-09 18:31发布

I want show dividers between menu items in android actionbar

Icon1 | Icon2 | icon3

my code for showing menu items is

<item
    android:id="@+id/menu_time"
    android:icon="@drawable/action_time_btn_stateful"
    android:title="time"
    peel:showAsAction="always"/>
<item android:id="@+id/menu_room_change"
      android:icon="@drawable/action_room_btn_stateful"
      android:title="change"
      peel:showAsAction="always"/>
<item
    android:id="@+id/menu_like_set"
    android:icon="@drawable/like_button"
    android:title="Like"
    peel:showAsAction="always" />

Thanks in advance.

2条回答
Luminary・发光体
2楼-- · 2019-09-09 19:11

Simply put, your actionbar in ICS and later version is limited to show 4 items in menu.
The rest of the items can be shown when you tap on overflow menu (vertical 3 dotted line).

So adding a divider between items counts divider is also a menu item.

Did you take a look at these already :)

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

ActionBar MenuItem Divider

I suggest get your icons with divider on their left or right based on your requirement.
Not a good practice. But let me know if you find a better solution :)

查看更多
家丑人穷心不美
3楼-- · 2019-09-09 19:22

Try setting custom style

<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>
查看更多
登录 后发表回答