Status bar color of main activity changes but othe

2019-08-25 03:03发布

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>

2条回答
Summer. ? 凉城
2楼-- · 2019-08-25 03:34

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.

查看更多
Luminary・发光体
3楼-- · 2019-08-25 03:48

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

查看更多
登录 后发表回答