How to change color of ActionBar's Title Text on Android 4.3 api 18

有些话、适合烂在心里 提交于 2019-11-30 15:50:42

问题


I am using appcompat v7 library to support action bars in api level 8 and up. I am trying to change the color of title text of action bar.

Color of title text is changing in GingerBread but when I run the app on my phone with JellyBean the color doesn't change.

On GingerBread Title Color changes to Red:

On JellyBean it remains black:

Here are my styles.xml:

styles.xml:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
        <item name="titleTextStyle">@style/TitleBarTextColor</item>
    </style>

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
    </style>
    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

styles.xml for v-11:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>

</resources>

styles.xml for v-14:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>
</resources>

Mainfest:

android:theme="@style/AppTheme" 

回答1:


Found Solution to my own problem :

I have to use android:actionBarStyle , android:titleTextStyle and android:textColor for api level 14 and up.

So the styles.xml for v-11 will be:

<resources>

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

    <style name="ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
        <item name="android:titleTextStyle">@style/TitleBarTextColor</item>
    </style>

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
    </style>
    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>



回答2:


I'll use the following within my styles for the current theme in order to update the text color in the ActionBar:

<item name="android:actionMenuTextColor">@color/Red</item>

which seems to work for me across the latest OS releases.



来源:https://stackoverflow.com/questions/22353414/how-to-change-color-of-actionbars-title-text-on-android-4-3-api-18

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!