Android actionbar sherlok doesn't show divider

六眼飞鱼酱① 提交于 2019-12-17 11:44:38

问题


I'm using the sherlok-actionbar and trying to apply a divider between the action buttons. I have th style but the dividers are not visible, why?

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light">
    <item name="abBackground">@drawable/actionbar_gradient</item>
    <item name="abIcon">@drawable/logo</item>       
    <item name="abDivider">@drawable/ab_divider</item>
</style>

Thanks!


回答1:


ActionBarSherlock v3.5 was updated to include the sources from Ice Cream Sandwich for all action-item related views and classes. This means that the rules for placing a divider between two action items follows the same rules as it would on ICS.

A divider would only be shown between the following:

  • Text-only followed by text-only
  • Icon-only followed by text-only
  • Text and icon followed by text-only

If you want to override this behavior (on pre-3.0 only) make the following change to ActionItemView.java:




回答2:


What you can do is to add a view next to the actionbar item that will look like the separator (works on all Android versions)

<item
    android:actionViewClass="com.example.ActionSeparatorView"
    android:showAsAction="always"
    android:title="@null"/>

and the ActionSeparatorView is a simple extension of the ImageView with the drawable you want to show as a separator

public class ActionSeparatorView extends ImageView {
public ActionSeparatorView (Context context) {
    super(context);
    setImageDrawable(getResources().getDrawable(R.drawable.separator));
  }
}


来源:https://stackoverflow.com/questions/9274259/android-actionbar-sherlok-doesnt-show-divider

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