Showing dividers between menu items in android actionbar

倖福魔咒の 提交于 2019-12-25 03:24:13

问题


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.


回答1:


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 :)




回答2:


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>


来源:https://stackoverflow.com/questions/24669708/showing-dividers-between-menu-items-in-android-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!