Search code examples
androidmaterial-designnavigation-drawerstatusbar

Making the color under the status bar match, when using Drawer Layout


I'm having the hardest time changing the color beneath the transparent status bar color. The transparency is fine when the drawer is open, but the color beneath is wrong. Different fragments are going to have different action bar colors.

fitsSystemWindow has no effect.

Changing the status bar color just makes it solid.

If I set a color with a lower alpha, it just mixes with the green (Primary Color Dark).

What is happening: (Color underneath is green)

full screenshot of incorrect colour closeup screenshot of incorrect colour


What I want is exactly like what is happening in the play store:

screenshot example 1 of correct colour from play store screenshot example 2 of correct colour from play store


Solution

  • The following should do what you want:

    • First make sure that your app theme in v21/style.xml has

      <item name="android:windowTranslucentStatus">true</item>
      
    • Use mDrawerLayout.setStatusBarBackgroundColor() for changing the background color of statusBar on fragment change instead of setStatusBarColor().

    • Make sure your coordinatorLayout doesn't contain the property android:fitsSystemWindows.