Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android actionbar sherlok doesn't show divider

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!

like image 397
TOMKA Avatar asked Feb 14 '12 09:02

TOMKA


2 Answers

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:

like image 71
Jake Wharton Avatar answered Oct 14 '22 15:10

Jake Wharton


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));
  }
}
like image 9
Krzysztof Avatar answered Oct 14 '22 14:10

Krzysztof