TextColorPrimary does not work on ActionBar on Android

Asked 1 years ago, Updated 1 years ago, 104 views

I am trying to change the background and text color of ActionBar on Android on Android Studio.
I was able to change it in ActionBar background colorPrimary, but I cannot change it even if I use textColorPrimary.
How do I change it?

<item name="colorPrimary">@color/colorPrimary</item>
<item name="android:textColor">@color/textColorPrimary</item>

Environment
Android Studio Ver 4.2.1

android android-studio

2022-09-30 19:19

1 Answers

The English version has answers
https://stackoverflow.com/questions/5861661/actionbar-text-color

However, if the ActionBar character cannot be changed with this content, it may be Toolbar, not ActionBar.
(If you create an app using templates in Android Studio, you may treat Toolbar like ActionBar.)
If within Activity

setSupportActionBar (binding.appBarMain.toolbar)

Check the layout/app_bar_main.xml if it is initialized as shown in .If androidx.appcompat.widget.Toolbar appears, you can change the color of the title in app:titleTextColor

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/Theme.MyApplication.AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android: id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/Theme.MyApplication.PopupOverlay"
        app:titleTextColor="@color/red"/>

</com.google.android.material.appbar.AppBarLayout>


2022-09-30 19:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.