Home » Android » Android ActionBar Text Color

Android ActionBar Text Color

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have xml like this:

<resources>

<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:titleTextStyle">@style/TitleColor</item>
</style>

<style name="MyActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#800000</item>
</style>

<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#000099</item>
</style>
</resources>

Background color is properly set, but title color does not change. Where did I make mistake?
Thanks!

How to&Answers:

Change it to this:

<resources>

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#800000</item>
        <item name="android:titleTextStyle">@style/TitleColor</item>
    </style>

    <style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">#000099</item>
    </style>
</resources>

Answer:

You can also change programmatically like this

ActionBar actionbar = getSupportedActiobar();
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));

Answer:

I’m using this

<resources>

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    <item name="actionBarStyle">@style/myTheme.ActionBar</item>
    <item name="actionMenuTextColor">@color/action_text_color</item>
</style>

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

<style name="myTheme.ActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="titleTextStyle">@style/myTheme.ActionBar.Text</item>
    <item name="background">@drawable/abc_tab_indicator_ab_holo</item>
    <item name="backgroundStacked">@drawable/abc_ab_transparent_dark_holo</item>
    <item name="backgroundSplit">@drawable/abc_ab_bottom_transparent_light_holo</item>
</style>

<style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/action_text_color</item>
</style>

Answer:

This is what worked for me …

<style name="MyActionBar"
    parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/titleBarBgColor</item>
    <item name="android:titleTextStyle">@style/EldTheme.ActionBar.TitleTextStyle</item>
    <item name="android:subtitleTextStyle">@style/EldTheme.ActionBar.TitleTextStyle</item>
    <!-- Support library compatibility -->
    <item name="background">@color/titleBarBgColor</item>
    <item name="titleTextStyle">@style/EldTheme.ActionBar.TitleTextStyle</item>
    <item name="subtitleTextStyle">@style/EldTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="EldTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/titleBarTextColor</item>
</style>