Changing the title color of an open Activity

Asked

Viewed 37 times

-1

I’m trying to change the color of the text of my Action Bar, but I’m not getting... I have researched here and elsewhere and the answer is always very similar to that answer:

Changing the title color of my application

However, whenever I change it, the Action Bar never changes the color of the text... I’ve been able to decrease the text, change the background... But the text insists on staying blank...

I’m going to put my entire code here to see if anyone can help me because I don’t know if there’s any data overlap going on:

Code from my themes file:

 <!-- Base application theme. -->
    <style name="Theme.App" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryVariant">@color/colorPrimaryVariant</item>
        <item name="colorOnPrimary">@color/colorPrimaryText</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/colorSecondary</item>
        <item name="colorSecondaryVariant">@color/colorSecondaryVariant</item>
        <item name="colorOnSecondary">@color/colorSecondaryText</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->

    </style>

    <style name="Theme.App.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <!-- Style usado no tema das activitys do manifest. -->
    <style name="Theme.App.BackActionBar" >
        <item name="actionBarStyle">@style/Widget.Theme.App.ActionBar.HomeAsUpActionBarStyle</item>

        <item name="windowActionBar">true</item>
        <item name="windowNoTitle">false</item>
    </style>


    <style name="Theme.App.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="android:textColorPrimary">@color/black</item>
    </style>


    <style name="Theme.App.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >
        <item name="android:textColorPrimary">@color/red</item>
    </style>


    <style name="Theme.App.Fullscreen" parent="Theme.App">
        <item name="android:actionBarStyle">@style/Widget.Theme.App.ActionBar.Fullscreen
        </item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowBackground">@null</item>
    </style>

    <style name="ThemeOverlay.App.FullscreenContainer" parent="">
        <item name="fullscreenBackgroundColor">@color/fullscreenBackgroundColor</item>
        <item name="fullscreenTextColor">@color/fullscreenTextColor</item>
    </style>

Code from my Styles file:

 <style name="Widget.Theme.App.ActionBar.Fullscreen" parent="Widget.AppCompat.ActionBar">
        <item name="android:background">@color/black_overlay</item>
    </style>

    <style name="Widget.Theme.App.ActionBar.HomeAsUpActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
        <item name="displayOptions">showTitle|homeAsUp</item>

        <!-- Title Text Color -->
        <item name="android:titleTextStyle">@style/MyActionBarTitleTextStyle</item>
        <item name="android:subtitleTextStyle">@style/MyActionBarSubTitleTextStyle</item>
        <item name="android:background">?attr/colorSecondary</item>
        <!-- Support library compatibility -->
        <item name="titleTextStyle">@style/MyActionBarTitleTextStyle</item>
        <item name="subtitleTextStyle">@style/MyActionBarSubTitleTextStyle</item>
        <item name="background">?attr/colorSecondary</item>

    </style>

    <style name="MyActionBarTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
        <item name="android:textColorPrimary">@color/red</item>

        <item name="android:textStyle">normal</item>
    </style>

    <style name="MyActionBarSubTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle">
        <item name="android:textColor">@color/red</item>
        <item name="android:textColorPrimary">@color/red</item>

        <item name="android:textStyle">normal</item>
    </style>

    <style name="Widget.Theme.App.ButtonBar.Fullscreen" parent="">
        <item name="android:background">@color/black_overlay</item>
        <item name="android:buttonBarStyle">?android:attr/buttonBarStyle</item>
    </style>

How I am adding theme in activitys in my manifest:

         <activity
            android:name=".TimeActivity"
            android:label="@string/label_TimeActivity"
            android:theme="@style/Theme.App.BackActionBar" />

And there’s more. If you’re going to vote no, at least let me know where I’m going wrong so I can learn from my mistakes, because I genuinely don’t know where I’m going wrong... It’s my second question where stack users negatively... and no one can answer me...

And it’s not like I just asked a free question on the website... As I said I researched! and even implementing these answers and others:

Changing Actionbar Color in Style

Change Actionbar title color

I didn’t get any results...

1 answer

0

Carlos, from what I saw of your code seems to be correct (but I didn’t test locally).

You tried to make the change programmatically, this way below?

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(getResources().getColor(R.color.red));
setSupportActionBar(toolbar);
  • Programmatically it works.... But the problem is that this way I can’t use the nightly theme

Browser other questions tagged

You are not signed in. Login or sign up in order to post.