[英]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.