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);
到目前为止,每个选项卡的 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 不是一个有效的属性
谢谢
最佳答案
您不应更改代码中的文本颜色。使用 color state list resource反而。
在资源中定义颜色选择器。在 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>
关于android - 如何更改 ActionBarSherlock Tab 文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13288514/