sandalone
sandalone

Reputation: 41749

ActionBar change color/drawable of selected tab only?

To change the color or background of all ACtionBar tabs, I can use actionBar.setStackedBackgroundDrawable().

But how can I change the color or drawable of selected tab? For example, the background color of tabs is black, but when I select some tab, I want it to be red.

Possible to do this as I haven't been able to find topics on this issue.

Upvotes: 1

Views: 3558

Answers (1)

Paul Burke
Paul Burke

Reputation: 25584

Replace the Selector being used for tabs:

<style name="Custom" parent="@style/Theme.Sherlock">
    <item name="actionBarTabStyle">@style/Widget.Custom.TabView</item>

    <item name="android:actionBarTabStyle">@style/Widget.Custom.TabView</item>
</style>

<style name="Widget.Custom.TabView" parent="@style/Widget.Sherlock.ActionBar.TabView">
    <item name="android:background">@drawable/your_custom_selector</item>
</style>

Check out the Drawable in ABS titled abs__tab_indicator_ab_holo.xml for reference on how to create your_custom_selector.

You want to change anything that has android:state_selected="true".

Upvotes: 5

Related Questions