主要 activity 的状态栏颜色发生变化,但其他活动状态栏颜色保持不变

Status bar color of main activity changes but other activities status bar color remains same

我如何将所有活动的状态栏颜色更改为黑色,因为此代码仅将主要 activity 的状态栏颜色更改为黑色,而其他活动中的状态栏颜色保持灰色。

<style name="CustomToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="overlapAnchor">false</item>
    <item name="android:dropDownVerticalOffset">-4dp</item>
    <item name="colorPrimaryDark">@color/black</item>
    <item name="colorAccent">#000000</item>
    <item name="android:textColorSecondary">@color/white</item>
</style>

您也必须在清单中为其他活动定义此主题

<activity
android:name=".YourActivityName"
android:theme="@style/CustomToolbarStyle"/>

您可以为所有需要黑色状态栏颜色的活动设置此主题 负责状态颜色的颜色是 colorPrimaryDark 在您的 colors.XML

中定义

默认情况下,Manifest 标签中设置的主题用于设置 activity 声明的没有任何主题的主题。

您应该在清单中的 应用程序的 主题属性中应用您提到的主题。

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:theme="@style/CustomToolbarStyle">
.....
</application>

并且此主题将被您在 Activity 标签的主题属性中设置的主题或从 Activity 中设置的主题覆盖s 布局,同样按主题属性。