Action Bar Sherlock, change colour of line under t

2019-05-23 05:00发布

问题:

How can I change the colour of the line that appears under the highlighted Action Bar Sherlocks tab.

It's default is an electric blue.

回答1:

Here an implementation based on the google i/o app implementation:

Set the theme style:

<style name="Theme.Styled" parent="Theme.Sherlock.Light">

    <item name="android:actionBarTabBarStyle">@style/Widget.Styled.TabBar</item>
    <item name="actionBarTabBarStyle">@style/Widget.Styled.TabBar</item>

</style>

 <style name="Widget.Styled.TabView" parent="Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@drawable/tab_white_ab</item>
</style>

Create a drawable like this - notice that in the google I/O app the non focused state is transparent - in the example below I changed transparent to green:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false"
    android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/tab_green_unselected"
             />
    <!--  android:drawable="@android:color/transparent"-->

<item android:state_focused="false"
    android:state_selected="true"
    android:state_pressed="false"
    android:drawable="@drawable/tab_white_selected" />

<!-- Focused states -->
<item android:state_focused="true"
    android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/item_focused" />
<item android:state_focused="true"
    android:state_selected="true"
    android:state_pressed="false"
    android:drawable="@drawable/tab_white_selected_focused" />

<!-- Pressed -->
<!--    Non focused states -->
<item android:state_focused="false"
    android:state_selected="false"
    android:state_pressed="true"
    android:drawable="@drawable/item_pressed" />
<item android:state_focused="false"
    android:state_selected="true"
    android:state_pressed="true"
    android:drawable="@drawable/tab_white_selected_pressed" />

<!--    Focused states -->
<item android:state_focused="true"
    android:state_selected="false"
    android:state_pressed="true"
    android:drawable="@drawable/item_focused" />
<item android:state_focused="true"
    android:state_selected="true"
    android:state_pressed="true"
    android:drawable="@drawable/tab_white_selected_pressed" />

Hope this helps.