Android ActionBar Sherlock - Remove divider betwee

2019-07-03 11:22发布

问题:

I'm trying to remove the divider between the tabs in an ActionBar (actually an ActionBarSherlock) altogether; i.e. no image between tabs and no gap between the tabs either (I'm using a tiled image background in the tabs). Ideally, I'd like the dividers removed in the XML, rather than in code.

I've tried a few approaches, but nothing seems to be working, such as:

<style name="Theme.MyTheme.ActionBarTab" parent="Widget.Sherlock.ActionBar.TabBar">
    <item name="android:divider">@null</item>
    <item name="divider">@null</item>
    <item name="actionBarDivider">@drawable/empty</item>
    <item name="android:showDividers">none</item>
</style>

回答1:

Turns out I was setting the wrong style. The android:showDividers attribute does work, but when it's applied to the style that inherits from the Widget.Sherlock.ActionBar.TabBar style. So the relevant bits of XML are:

<style name="Theme.Client" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="android:actionBarTabBarStyle">@style/Theme.Client.ActionBarTabBar</item>
    <item name="actionBarTabBarStyle">@style/Theme.Client.ActionBarTabBar</item>
</style>

<style name="Theme.Client.ActionBarTabBar" parent="Widget.Sherlock.ActionBar.TabBar">
    <item name="android:background">@drawable/tab_bar_bg_tiled</item>
    <item name="background">@drawable/tab_bar_bg_tiled</item>
    <item name="android:showDividers">none</item>
</style>