2014-01-19 77 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

相關問題