我正在尝试为我的应用程序实现夜间模式。
在我的整个应用程序中,?android:attr/textColorPrimary
夜间模式为白色,白天模式为黑色。就在我的通知中,它总是黑色的。在 Android Studio 布局预览中,文本是白色的。(如果相关,我将从前台服务发送通知。)
我可以为@color/white
用于文本的通知制作夜间模式布局文件,但为什么它不适用于属性?
我正在尝试为我的应用程序实现夜间模式。
在我的整个应用程序中,?android:attr/textColorPrimary
夜间模式为白色,白天模式为黑色。就在我的通知中,它总是黑色的。在 Android Studio 布局预览中,文本是白色的。(如果相关,我将从前台服务发送通知。)
我可以为@color/white
用于文本的通知制作夜间模式布局文件,但为什么它不适用于属性?
我找到了原因。我必须将通知布局的主题设置为 Theme.MaterialComponents.DayNight。
除了@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">