Italo Rocha
Italo Rocha

Reputation: 23

Customize the Status Bar

I'm trying to change the colors of my StatusBar, when I try to alterate the colorPrimaryDark (first bar, where stays batery, tima, date, etc...) the color do not change.

I've created a xml with the values of the colors that I use

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

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

In other words, I can change colors of my background, titlebar, text, but when I try to change colorPrimaryDark, no matter what the value entered the color never change, could someone help me please?

Upvotes: 2

Views: 75

Answers (4)

Uzair Qaiser
Uzair Qaiser

Reputation: 156

Edit Your Style.Xml and add this within the resources tags:

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colortoolbar</item>
    <item name="colorPrimaryDark">@color/colortoolbar</item>
    <item name="colorAccent">@color/colortoolbar</item>

</style>

where colortoolbar is already defined in my colors.xml. You can define your own color.

Upvotes: 0

Flutterian
Flutterian

Reputation: 1781

There are various ways to change color of status bar. Below is my solution.

  1. Edit your style.xml as below. You can directly add android:statusBarColor tag to your xml.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:statusBarColor">#d9591b</item>
</style>

Note -: android:statusBarColor is available in minsdk version 21. It will not work below api level 21. You need to modify your gradle file. Change minSdkVersion to 21.

Upvotes: 0

kimkevin
kimkevin

Reputation: 2222

Remove android tag and try it again.

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="AppTheme" parent="android:Theme.Material.Light">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="textColorPrimary">@color/textprimary</item>
  </style>
</resources>

Upvotes: 0

KeLiuyue
KeLiuyue

Reputation: 8237

Change your theme to this.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

Upvotes: 1

Related Questions