android - 工具栏 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>
解决方案
您可以使用:
<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>
推荐阅读
- r - R中带有tesseract的OCR无法识别所有换行符
- ruby-on-rails - 如果我可以在 redmine 控制器中的“before action”之后添加“if”
- java - Spring构建CSV字符串并用它下载一个文件
- jquery - 如何检查jquery验证器中每个验证修复中剩余多少无效字段
- excel - 循环遍历 Excel 工作表中的单元格
- android - 如何通过广播接收器获取发送的短信详细信息
- javascript - 批量更新,txt文件名与第三行内容(第三行内)
- scikit-learn - 使用预定义的拆分重新调整网格搜索的属性?
- arrays - 如何使用嵌套数组创建 JSON 响应
- python - lxml object identifiers appear to be reused while objects are alive