Status bar color of main activity changes but othe

2019-08-25 03:34发布

问题:

How do i change my status bar color to black for all activities as this code only changes status bar color of main activity to black and color of status bar in other activities remain grey.

<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>

回答1:

By default the theme which is set in Manifest's tag is used to set theme of an activity declared which not having any theme.

You should apply your mentioned theme in Application's theme attribute in Manifest.

<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>

And this theme will be overriden by the theme which you set in Activity tag's theme attribute in Manifest or theme which is set from Activity's layout, again by theme attribute.



回答2:

You have to define this theme for other activities too in your manifest

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

You can set this theme for all the activities in which you want black status bar color the color responsible for status color is colorPrimaryDark defined in your colors.XML