工具栏TitleTextColor在黑暗模式下不会更改 [英] Toolbar TitleTextColor not changing in dark mode

查看:95
本文介绍了工具栏TitleTextColor在黑暗模式下不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在集成黑暗模式,我有折叠式工具栏和包裹在appbarlayout中的工具栏, 问题是当设置深色模式时我尝试将工具栏标题颜色设置为白色,而在浅色模式下却不起作用,颜色会相应显示,我尝试了几乎所有操作,但我不知道到底在发生什么,我有颜色和颜色的夜间文件夹,我为它们都设置了颜色并将其添加到我的工具栏中,但是它没有任何改变,如果有任何帮助,我将深表感谢,谢谢

I'm integrating Dark Mode , i have Collapsing toolbar and toolbar which are wrapped in an appbarlayout , the issue is when i try to set the toolbar title color into white when dark mode is set , it is not working meanwhile in light mode , the color shows accordingly , i tried almost everything but i don't know exactly what is happening , i have color and color night folders and i set up the color for both and added it to to my toolbar but it didn't change anything , if any one could help , i ll deeply appreciate it , thank you

  • 这是在折叠标题之前

  • This is before collapsing title

并且在我折叠要在工具栏中设置的标题后,它不显示白色(这是我想要在黑暗模式下显示工具栏标题颜色的颜色)

And after i collapse the title to be set in toolbar , it dosn't show white ( which is the color i want in dark mode for the toolbar title color )

这是我的xml代码

 <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>
      

      推荐答案

      android会根据主题从浅色主题的文件夹values和深色主题的values-night中选择正确的颜色,但是没有toolbarcolor在那些xml文件中,因此它总是从AppTheme

      as android chooses the correct color based on themes from the folder values in light theme and from values-night in dark theme but there is no toolbarcolor in those xml files so it always chooses it from the toolbarcolor of AppTheme

      所以我认为以下方法可以工作(如果不行,请告诉我)

      so i think the following can work (tell me if it doesn't)

      添加到valuescolors.xml

      <color name="toolbarcolor">your day color</color>

      添加到values-nightcolors.xml

      <color name="toolbarcolor">your night color</color>

      ,您可以从styles.xml

      这篇关于工具栏TitleTextColor在黑暗模式下不会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆