2

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

在我的整个应用程序中,?android:attr/textColorPrimary夜间模式为白色,白天模式为黑色。就在我的通知中,它总是黑色的。在 Android Studio 布局预览中,文本是白色的。(如果相关,我将从前台服务发送通知。)

我可以为@color/white用于文本的通知制作夜间模式布局文件,但为什么它不适用于属性?

4

2 回答 2

2

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

于 2020-04-27T18:03:22.963 回答
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">
于 2020-06-22T15:45:24.113 回答