首页 > 解决方案 > 工具栏 TitleTextColor 在暗模式下没有变化

问题描述

我正在集成暗模式,我有折叠工具栏和工具栏,它们包含在 appbarlayout 中,问题是当我尝试在设置暗模式时将工具栏标题颜色设置为白色时,它在亮模式下不起作用,颜色相应地显示,我几乎尝试了所有东西,但我不知道到底发生了什么,我有颜色和颜色夜间文件夹,我为两者设置颜色并将其添加到我的工具栏但它没有改变任何东西,如果任何人都可以提供帮助,我将不胜感激,谢谢

 <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".View.MealDetails">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appbarlaout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/collapsingtoolbar"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/toolbarcolor"
                app:titleEnabled="true"
                app:title="@{details.strMeal}"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="190dp"
                    app:mealDetailsImg="@{details.strMealThumb}"
                    android:background="@drawable/noimg"
                    tools:ignore="ContentDescription" />
                    <com.google.android.material.appbar.MaterialToolbar
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:id="@+id/mealdetailstoolbar"
                        app:menu="@menu/addfavmenu"
                        app:navigationIcon="@drawable/arrow_back_black"
                        app:layout_collapseMode="pin" />

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

        </com.google.android.material.appbar.AppBarLayout>
<resources>
    <color name="colorPrimary">#6200EE</color> 
    <color name="colorPrimaryDark">#000000</color> // changing status bar color 
    <color name="colorAccent">#000000</color> // changing icons color 
    <color name="textColorPrimary">#000000</color> // i m not sure if this is correct but i think it is for toolbar text ( i could be wrong )
    <color name="ratetextcolor">#000000</color> /// this is to change rate text color
    <color name="iconscolor">#000000</color> // this is for icons color
    <color name="faviconcolor">#d10d06</color> // i have an icon which i wanted to settle to red in light mode and blue in dark mod
    <color name="categoryareacolor">#000000</color> //textviews
    <color name="headerColor">#ffffff</color>
</resources>

<resources>
        <color name="colorPrimary">#6200EE</color>
        <color name="colorPrimaryDark">#6200EE</color>
        <color name="colorAccent">#6200EE</color>
        <color name="textColorPrimary">#ffffff</color>
        <color name="ratetextcolor">#ffffff</color>
        <color name="iconscolor">#3266a8</color>
        <color name="faviconcolor">#3266a8</color>
        <color name="categoryareacolor">#000000</color>
</resources>

标签: androidandroid-toolbarandroid-themeandroid-collapsingtoolbarlayout

解决方案


您可以使用:

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

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:fitsSystemWindows="true"
            app:contentScrim="@color/..."
            android:theme="@style/CollapsingToolbarLayout_Overlay"
            >

    

和:

<style name="CollapsingToolbarLayout_Overlay">
    <!-- Title text color -->
    <item name="android:textColorPrimary">@color/....</item>
    <!-- Toolbar up color -->
    <item name="colorControlNormal">@color/...</item>
</style>   

在此处输入图像描述 在此处输入图像描述


推荐阅读