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

旧巷老猫 提交于 2019-12-11 18:15:48

问题


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



来源:https://stackoverflow.com/questions/51142315/status-bar-color-of-main-activity-changes-but-other-activities-status-bar-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!