0

我想自定義選項卡這樣custom tab style的Android主題化動作條選項卡

即所選選項卡將有一個白色背景,而一個未選中的選項卡將有一個綠色的背景。

直到現在,我能夠實現

what I have done

實現這個我做了以下爲我的風格: -

<resources> 
    <style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"> 
     <item name="android:background">@color/sa_green</item> 
     <item name="android:backgroundStacked">@color/stacked_green</item> 
     <item name="android:backgroundSplit">@color/sa_green</item> 
    </style> 

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
     <item name="android:actionBarStyle">@style/ActionBar</item> 
    </style> 
</resources> 

color.xml

<resources> 
    <color name="sa_green">#14a804</color> 
    <color name="stacked_green">#118504</color> 
    <color name="accent_green">#97e08f</color> 
</resources> 

如何刪除b指示燈並根據選擇哪個標籤更改背景?

+0

https://developer.android.com/training/basics/actionbar/styling.html#CustomTabs – 2Dee 2014-09-11 11:25:57

+0

@ 2Dee我看到的例子,但無法正確地實現它。你能指點我的任何工作的例子嗎? – 2014-09-11 12:05:08

回答

1

您需要一個選擇器xml,而不僅僅是@ color/sa_green。選擇器會根據其狀態告訴選項卡使用的顏色。

你可以去那樣簡單:

繪製/ tab_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="false" 
     android:background="@color/green" /> 
    <item android:state_pressed="true" 
     android:drawable="@color/white" /> 
</selector> 

然後你只需把

<item name="android:actionBarTabStyle">@style/ActionBar</item> 

在你的主題

,並宣佈在你的風格ActionBar中,像這樣:

<style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.TabView"> 
    <item name="android:background">@drawable/tab_selector</item> 
</style> 

這應該是它