我想在我的应用中实现深色主题;它在 mainactivity 中有一个工具栏,在其他 Activity 中有一个操作栏。我在 values/styles.xml 中实现了深色主题,如下所示:
<resources>
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="colorPrimary">@color/primary_material_dark</item>
<item name="colorPrimaryDark">@color/primary_dark_material_dark</item>
<item name="colorAccent">@color/material_deep_teal_200</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay"parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
这样做之后,我的应用程序变成了深色主题,但主要活动的工具栏颜色不同,其他活动的操作栏颜色不同。而且,在进行另一项活动时,也会出现一种眨眼。
在我的主要活动中,有recyclerview制作的cardview;从这张照片开始,我想实现深色主题。
我不知道为什么从主要活动到其他活动(其他活动有操作栏)时工具栏的颜色会发生变化,而从一个活动到另一个活动时背景会闪烁。
我还想将cardview布局颜色的整个背景颜色设置为给定图片。我尝试这样做很多次,但没有发生背景闪烁:(
顺便说一句,这是我工具栏的 xml(app_bar_main.xml):
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
..
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton.../>
</androidx.coordinatorlayout.widget.CoordinatorLayout>