简体   繁体   中英

Android. ActionBar. How to change ActionBar title color?

I am trying to change ActionBar title color. I tried different ways to do it. But I could not solve this problem. I have created my own actionbar theme in values/styles.xml and values-14/styles.xml

values/styles.xml

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">   
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@color/grey_actionbar_background</item>
    <item name="icon">@drawable/ic_launcher</item>
    <item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
</style>

<style name="MyActionBarTabText" parent="@style/Widget.AppCompat.Light.ActionBar.TabText">
    <item name="android:textColor">@color/grey_text</item>
</style>

values-v14/styles.xml

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/grey_actionbar_background</item>
    <item name="background">@color/grey_actionbar_background</item>
    <item name="android:icon">@drawable/ic_launcher</item>
    <item name="icon">@drawable/ic_launcher</item>
    <item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
</style>

<style name="MyActionBarTabText" parent="@style/Widget.AppCompat.Light.ActionBar.TabText">
    <item name="android:textColor">@color/grey_text</item>
</style>

grey_text color is #58585A . But when I am running on 4.3 device, ActionBar title color is F3F3F3 .

I am wondering why this is happening. How to solve this problem?

在此处输入图片说明

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    ...
</style>

<style name="ActionBar" parent="@android:style/Widget.ActionBar">
  <item name="android:titleTextStyle">@style/ActionBar.Title</item>
  <item name="android:subtitleTextStyle">@style/ActionBar.Subtitle</item>
  ...
</style>

<style name="ActionBar.Title">
  <item name="android:textColor">@color/my_color</item>
</style>

<style name="ActionBar.Subtitle">
  <item name="android:textColor">@color/my_color</item>
</style>

只需尝试Activity类“ setTitleColor(int color)”的方法

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM