Action Bar Sherlock, change colour of line under tab?

吃可爱长大的小学妹 提交于 2019-12-22 13:47:59

问题


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.



来源:https://stackoverflow.com/questions/12108057/action-bar-sherlock-change-colour-of-line-under-tab

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