[英]How to change ActionBarSherlock Tab Text color?
adapter.addTab(getSupportActionBar().newTab().setText("Tab-1"),
Tab1.class, null);
adapter.addTab(getSupportActionBar().newTab().setText("Tab-2"),
Tab2.class, null);
adapter.addTab(getSupportActionBar().newTab().setText("Tab-3"),
Tab3.class, null);
截至目前,每個Tab的TextColor都是白色的。 我希望它在未選中時為灰色,在選中時為白色。 那么,我如何更改onTabSelected或onTabUnselected中的文本顏色。
或者我應該使用setCustomView作為選項卡? 在這里,TextSize和所有這些都需要處理
<style name="my_ActionBarTabStyle" parent="@style/Widget.Sherlock.ActionBar.TabView">
<item name="background">@drawable/tab_indicator_ab_wicfy</item>
<item name="android:background">@drawable/tab_indicator_ab_wicfy</item>
<item name="android:textColor">@color/black</item>
</style>
我試着用
<item name="textColor">@color/black</item>
但它給我一個錯誤, textColor不是一個有效的屬性
謝謝
您不應該從代碼中更改文本顏色。 請改用顏色狀態列表資源 。
在資源中定義顏色選擇器。 在res/color/
目錄中定義xml文件。 該文件將包含:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- use when selected -->
<item android:state_selected="true" android:color="#fff" />
<!-- otherwise use -->
<item android:color="#888" />
</selector>
然后在樣式中設置文本顏色:
<item name="android:textColor">@color/my_color_selector</item>
編輯:
您必須在樣式中的正確位置設置文本顏色! 在(android:)actionBarTabTextStyle
設置textColor。 主題必須包含:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
...
<!-- define text style for tabs -->
<item name="actionBarTabTextStyle">@style/MyTabTextStyle</item>
<item name="android:actionBarTabTextStyle">@style/MyTabTextStyle</item>
...
</style>
然后在選項卡文本樣式中設置文本顏色:
<style name="MyTabTextStyle" parent="Widget.Sherlock.ActionBar.TabText" >
<item name="android:textColor">@color/my_color_selector</item>
</style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.