我正在尝试为我的应用程序实现夜间模式。
在我的整个应用程序中。?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">