如何改变ActionBarSherlock标签文本颜色? [英] How to change ActionBarSherlock Tab Text color?

查看:177
本文介绍了如何改变ActionBarSherlock标签文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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和所有需要被照顾

Or should i go with setCustomView for the tab?? Here again the TextSize and all needs to be taken care of

<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>

但它给我的错误文字颜色不是一个有效的属性。

感谢您

推荐答案

您不应该改变从code文本颜色。使用颜色状态列表资源代替。

You should not change text color from the code. Use color state list resource instead.

定义资源的颜色选择。定义 RES /彩色/ 目录中的XML文件。该文件将包含:

Define the color selector in resources. Define a xml file in res/color/ directory. The file will contain:

<?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>

然后设置在样式的文本颜色:

And then set the text color in a style:

<item name="android:textColor">@color/my_color_selector</item>

编辑:

您必须设置文本颜色在样式的正确的地方!坐落于的文字颜色(安卓)actionBarTabTextStyle 。主题必须包含:

You have to set the text color in the right place in the styles! Set the textColor in (android:)actionBarTabTextStyle. The theme has to contain:

<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>

然后设定选项卡上的文本样式的文本颜色:

Then set the text color in the tab text style:

<style name="MyTabTextStyle" parent="Widget.Sherlock.ActionBar.TabText" >
    <item name="android:textColor">@color/my_color_selector</item>
</style>

这篇关于如何改变ActionBarSherlock标签文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆