如何更改操作栏选项卡文本颜色

时间:2014-07-07 07:44:58

标签: android android-actionbar textcolor

我需要更改操作栏选项卡文本颜色。所以操作栏选项卡文本颜色显示为黑色。但我需要将其更改为白色。

清单:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fth.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />

    <application
        android:name="com.sit.fth.app.GemsApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"

         android:theme="@android:style/Theme.Holo.Light" >
        <activity
            android:name="com.sit.fth.activity.SplashActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        </activity>

    </application>

</manifest>   

RES /值/ styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
     -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
         -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">

        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="GridLayout">
        <item name="android:drawSelectorOnTop">true</item>
        <item name="android:listSelector">@drawable/photogrid_list_selector</item>
    </style>

    <style name="CustomRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/custom_ratingbar</item>
         <item name="android:minHeight">20dip</item>
                <item name="android:maxHeight">20dip</item>
    </style>


    <style name="CustomTheme" parent="@android:style/Theme">
    <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
</style>

<style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
    <item name="android:textAppearance">@style/CustomTabWidgetText</item>
</style>

<style name="CustomTabWidgetText" 
    parent="@android:style/TextAppearance.Widget.TabWidget">
    <item name="android:textSize">12sp</item>
   <!--  <item name="android:textStyle">bold</item> -->
</style>


</resources>

在res / color.xml中:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <drawable name="list_bg_normal">#00000f</drawable>
    <drawable name="list_bg_normal_audio">#ededed</drawable>
     <drawable name="list_bg_pressed_audio">#FFFFFF</drawable>
    <drawable name="list_bg_pressed">#848484</drawable>
     <color name="grid_state_pressed">#BB7dbcd3</color>
    <color name="grid_state_focused">#777dbcd3</color>
    <drawable name="app_theme_bg">#F5F5FA</drawable>

     <color name="title_detail_color">#000000</color>
    <color name="duration_color">#e4e4e4</color>
    <color name="content_color">#454545</color>

</resources>

任何人都可以帮助我。谢谢。

2 个答案:

答案 0 :(得分:16)

在AppTheme中声明:

<item name="android:actionBarTabTextStyle">@style/tabtextcolor</item>

然后是样式声明:

<style name="tabtextcolor" parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
    <item name="android:textColor">@android:color/white</item>
</style>

答案 1 :(得分:1)

在我们的主题中使用它来设置操作栏文本颜色:

<item name="titleTextStyle">@style/ActionBar.CustomTitle</item>

<!-- ActionBar title text -->
    <style name="ActionBar.CustomTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/title_detail_color</item>
        <!-- The textColor property is backward compatible with the Support Library -->
    </style>

很抱歉,这是针对您使用AppCompat支持库的情况。

你可以使用一般:

<!-- ActionBar title text -->
    <style name="ActionBar.CustomTitle"
           parent="@style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@color/title_detail_color</item>
    </style>

此外,您可以尝试一些与您当前主题相匹配的其他主题,而不是Holo。 您还可以阅读官方文档: https://developer.android.com/training/basics/actionbar/styling.html