How to change the color of the Statusbar

Asked

Viewed 1,354 times

1

I am trying to change the colors of my Statusbar, but when trying to change the colorPrimaryDark (first bar, where it is battery, time, etc...) the color is not changed.

I created an xml with the values of the colors used

Colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name = "primary">#162d50</color>
<color name = "primary_dark">#010101</color>
<color name = "textprimary">#FFFFFF</color>


</resources>

And my Styles.xml is like this

Styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppTheme" parent="android:Theme.Material.Light">

        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:textColorPrimary">@color/textprimary</item>


</style>

</resources>

I am able to change all colors, background, title bar color, text color, however colorPrimaryDark, regardless of the value entered does not change the color, remains always black, someone could help me please?

1 answer

2

To change the color of the Statusbar you must use the attribute android:statusBarColor.

<style name="AppTheme" parent="android:Theme.Material.Light">

    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:textColorPrimary">@color/textprimary</item>

    <item name="android:statusBarColor">@color/cor_da_statusbar</item>
</style>

References:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.