为什么夜间模式通知中的android:attrtextColorPrimary是黑色的?

问题描述 投票:0回答:1

我正在尝试为我的应用程序实现夜间模式。

在我的整个应用程序中。?android:attr/textColorPrimary 夜间模式下是白色的,白天模式下是黑色的。只是在我的通知中,它一直是黑色的。在Android Studio布局预览中,文字是白色的。(如果有关系的话,我是从前台服务发送通知的。)

我可以为通知制作一个夜间模式布局文件,其中我使用了 @color/white 的文本,但为什么它不能与属性一起工作?

android android-notifications android-night-mode
1个回答
1
投票

我已经找到原因了。我必须将通知布局的主题设置为Theme.MaterialComponents.DayNight。


0
投票

除了@Colin的回答,这是一个例子片段,它是如何做到的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:theme="@style/Theme.MaterialComponents.DayNight">
© www.soinside.com 2019 - 2024. All rights reserved.