2014-01-19 79 views
2

我需要更改选项卡的指标的颜色,但我没有设法做到这一点。 有谁知道该怎么做? 这是我stiles.xml更改IndicatorColor默认选项卡

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    <item name="android:actionBarTabTextStyle">@style/MyCustomTabView</item> 
    <item name="android:ratingBarStyleIndicator">@style/indicator_color</item> 
    <item name="android:actionBarTabStyle">@style/CustomActionBarTheme</item> 
</style> 
<style name="MyCustomTabView" parent="Theme.AppCompat.Light"> 
    <item name="android:actionBarItemBackground">@style/indicator_color</item> 
    <item name="android:textColor">#ffffff</item> 
    <item name="android:textSize">12dp</item> 
    <item name="android:textStyle">bold</item> 
    <item name="android:backgroundStacked">#ffffff</item> 
</style> 
<style name="indicator_color"> 
    <item name="android:background">#ffffff</item> 
</style> 
<style name="CustomActionBarTheme" 
    parent="Theme."> 
    <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item> 
</style> 

<!-- ActionBar tabs styles --> 
<style name="MyActionBarTabs" 
    parent="Theme.AppCompat.Light"> 
    <!-- tab indicator --> 
    <item name="android:background">@drawable/actionbar_tab_indicator</item> 
</style> 

,这是actionbar_tab_indicator.xml:提前

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- STATES WHEN BUTTON IS NOT PRESSED --> 
<!-- Non focused states --> 
<item android:state_focused="false" android:state_selected="false" 
    android:state_pressed="false" 
    android:drawable="@drawable/abc_ab_bottom_solid_light_holo" /> 
<item android:state_focused="false" android:state_selected="true" 
    android:state_pressed="false" 
    android:drawable="@drawable/abc_ab_bottom_solid_light_holo" /> 

<!-- Focused states (such as when focused with a d-pad or mouse hover) --> 
<item android:state_focused="true" android:state_selected="false" 
    android:state_pressed="false" 
    android:drawable="@drawable/abc_ab_bottom_solid_light_holo" /> 
<item android:state_focused="true" android:state_selected="true" 
    android:state_pressed="false" 
    android:drawable="@drawable/abc_ab_bottom_solid_light_holo" /> 


<!-- STATES WHEN BUTTON IS PRESSED --> 

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

<!-- Focused states (such as when focused with a d-pad or mouse hover) --> 
<item android:state_focused="true" android:state_selected="false" 
    android:state_pressed="true" 
    android:drawable="@drawable/abc_ab_bottom_solid_light_holo" /> 
<item android:state_focused="true" android:state_selected="true" 
    android:state_pressed="true" 
    android:drawable="@drawable/abc_ab_bottom_solid_light_holo" /> 
</selector> 

感谢。

回答

1

要更改用于导航选项卡的指示符,请创建一个覆盖actionBarTabStyle属性的活动主题。此属性指向另一个样式资源,其中您将覆盖应指定可绘制状态列表的背景属性。

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <!-- the theme applied to the application or activity --> 
    <style name="CustomActionBarTheme" 
      parent="@style/Theme.Holo"> 
     <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item> 
    </style> 

    <!-- ActionBar tabs styles --> 
    <style name="MyActionBarTabs" 
      parent="@style/Widget.Holo.ActionBar.TabView"> 
     <!-- tab indicator --> 
     <item name="android:background">@drawable/actionbar_tab_indicator</item> 
    </style> 
</resources> 

了解更多here

0

你可以改变这样的TabWidget背景(这可能是你在说什么):

如果这是你的风格:

<style name="indicator_color"> 
    <item name="android:background">@android:color/black</item> 
</style> 

使用方法如下:

<TabWidget 
       style="@style/indicator_color" 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       > 
      </TabWidget> 

另请注意,#ffffff是白色。所以你可能看不到效果。

+0

这不是我的情况,我正在使用默认的ActionBar Tab + Swipe Views – Pier

相关问题