How to change the color of tab 'underbar' in actionbarsherlock

前端 未结 2 1727
执笔经年
执笔经年 2020-12-28 19:08

Ok i\'m loosing more sanity then ever. I can\'t find/understand how to style the damn thing. I managed to change the background of the tab itself but I can\'t cahnge the col

相关标签:
2条回答
  • 2020-12-28 19:31

    I found that for the background it's better to copy the drawables (9 patches and xml) found on the Android SDK res directory and change it to have the color you like.

    They use a background with the bottom bar included, so I don't think it's possible to change the bottom bar alone.

    Here's what I have, working with green color for the bottom bar:

    <style name="customTabStyle" parent="Widget.Sherlock.ActionBar.TabView">
        <item name="android:showDividers">none</item>
        <item name="android:measureWithLargestChild">true</item>
        <!-- This was a copy from the sdk drawable -->
        <item name="android:background">@drawable/tab_indicator</item>
    
        <item name="background">@drawable/tab_indicator</item>
        <item name="android:gravity">center</item>
        <item name="android:textStyle">normal</item>
    </style>
    
    
    <style name="customTabBar" parent="Widget.Sherlock.ActionBar.TabBar">
        <item name="android:showDividers">middle</item>
    
        <item name="android:divider">@drawable/tab_divider</item>
        <item name="divider">@drawable/tab_divider</item>
    
        <item name="android:dividerPadding">10dip</item>
    
        <item name="android:background">@drawable/tab_bg</item>
    </style>
    

    The tab indicator looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <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_unselected" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected" />
    
    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_focused" />
    
    <!-- Pressed -->
    <!--    Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed" />
    
    <!--    Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed" />
    </selector>
    

    I hope it helps!

    0 讨论(0)
  • 2020-12-28 19:38

    Use ActionbarStyleGenerator to style the Actionbar. This is by far the simplest and most intuitive way.

    How to:

    1. Use the UI to select colors for different items
    2. Once done click on "DOWNLOAD .ZIP"
    3. The ZIP file contains resource files that you have to copy in your project res/layout and res/drawableXXXX folders
    0 讨论(0)
提交回复
热议问题