4

I'm try to developing an app with a navigation drawer from a template found on github.

In style.xml i have:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#ff0000</item>
    <item name="colorPrimaryDark">#0000ff</item>

main

and the status bar in navigation drawer is ok. main

When i click the button it runs this command: getWindow().setStatusBarColor(Color.GREEN); main

Now the status bar color in navigation drawer is no more translucent main

How restore status bar color to translucent?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3744384_
  • 337
  • 3
  • 15

1 Answers1

0

The difference is that the xml defined colors colorPrimary and colorPrimaryDark are not really used to directly set the status bar color.

Actually the statusbar is completely transparent all the time and only the underlaying View is colored. Thats why it can have another color on the left than on the right side (have a look at your second screenshot). If you now call getWindow().setStatusBarColor(..) you indeed color the statusbar directly and over-draw the color of both Views. So it needs to stay transparent!

What you really want to do, is changing the color of the View underlaying the status bar, which is done with the ScrimInsetsFrameLayout class.
Have a look at this question and this class from the library you provided
There you should find all the necessary information to change only the color of the area you want to.


In case you really just want to reset the color:

getWindow().setStatusBarColor(Color.TRANSPARENT);
Community
  • 1
  • 1
bricklore
  • 4,125
  • 1
  • 34
  • 62