CoordinatorLayout not drawing behind status bar even with windowTranslucentStatus and fitsSystemWindows CoordinatorLayout not drawing behind status bar even with windowTranslucentStatus and fitsSystemWindows android android

CoordinatorLayout not drawing behind status bar even with windowTranslucentStatus and fitsSystemWindows


edit for future readers: there's a lot of good information on the subject and the issue on the comments too, make sure to read through them.

original answer:Your theme is wrong, that's why.Unfortunately, there're differences on how to activate in in Kitkat or Lollipop. On my code I did it in Java, but you can also achieve it in XML if you want to play with the V21 folders on your resources tree. The name of the parameters will be very similar to the Java counterparts.

Delete the android:windowTranslucentStatus from your XML and in Java use like that:

   public static void setTranslucentStatusBar(Window window) {      if (window == null) return;      int sdkInt = Build.VERSION.SDK_INT;      if (sdkInt >= Build.VERSION_CODES.LOLLIPOP) {         setTranslucentStatusBarLollipop(window);      } else if (sdkInt >= Build.VERSION_CODES.KITKAT) {         setTranslucentStatusBarKiKat(window);      }   }  @TargetApi(Build.VERSION_CODES.LOLLIPOP)   private static void setTranslucentStatusBarLollipop(Window window) {      window.setStatusBarColor(             window.getContext()                   .getResources()                   .getColor(R.color. / add here your translucent color code /));   }   @TargetApi(Build.VERSION_CODES.KITKAT)   private static void setTranslucentStatusBarKiKat(Window window) {      window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);   }

then you can call from your activity setTranslucentStatusBar(getWindow());

edit:

making the status bar translucent and drawing behind it (for some reason I cannot understand) are two separate tasks in Android.

I've looked more on my code and I'm for sure have A LOT more android:fitsSystemWindows="true" on my layout than just the CoordinatorLayout.

below are all the Views on my layout with android:fitsSystemWindows="true" on them:

  • CoordinatorLayout
  • AppBarLayout
  • CollapsingToolbarLayout
  • ImageView (with the background image)
  • FrameLayout (with the content of the header)

so my suggestion is to just test/try filling up android:fitsSystemWindows="true" on your XML.


  1. If I want to draw behind StatusBar I use CoordinatorLayout as most parent view of Activity (android:fitsSystemWindows="false")

styles.xml(v21)

<style name="MyTheme.NoActionBar.TransparentStatusBar">        <item name="android:windowDrawsSystemBarBackgrounds">true</item>        <item name="android:statusBarColor">@android:color/transparent</item>        <item name="android:windowTranslucentStatus">true</item>    </style>

Then If you want to change statubarcolor, you have to remove TRANSLUENT_FLAG like this

Window window = activity().getWindow();        if(showTransluent){            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);            window.setStatusBarColor(Color.TRANSPARENT);        }else {            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);            window.setStatusBarColor(ContextCompat.getColor(activity(), R.color.colorPrimaryDark));        }
  1. If I want StatusBar to be transluent and simultanieousy kepping view away from hidding behind StatusBar I use as most parent view FrameLayout with argument

My styles.xml(v21) look like

<resources>    <style name="AppTheme.NoActionBar">        <item name="windowActionBar">false</item>        <item name="windowNoTitle">true</item>        <item name="android:windowDrawsSystemBarBackgrounds">true</item>    </style>    <style name="AppTheme.NoStatusBar" parent="AppTheme.NoActionBar">        <item name="android:windowTranslucentStatus">true</item>        <item name="android:windowTranslucentNavigation">true</item>        <item name="windowActionBarOverlay">true</item>        <item name="android:windowActionBarOverlay">true</item>    </style></resources>

And styles.xml

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

Maybe the point key here is to be sure that you use AppCompactActivity as well as you use Theme.AppCompact as root for your styles.


This was really confusing for me but I eventually figured it out for my combination of views which looks like this:

<android.support.v4.widget.SwipeRefreshLayout - **no fitsSystemWindow set**<android.support.design.widget.CoordinatorLayout- android:fitsSystemWindows="true"<android.support.design.widget.AppBarLayout - android:fitsSystemWindows="true"<android.support.design.widget.CollapsingToolbarLayout - android:fitsSystemWindows="true"<RelativeLayout - android:fitsSystemWindows="true"<ImageView - android:fitsSystemWindows="true"

I also used the methods posted by Budius in my app to get the transparent status bar working:

Delete the android:windowTranslucentStatus from your XML and in Java use like that:

   public static void setTranslucentStatusBar(Window window) {      if (window == null) return;      int sdkInt = Build.VERSION.SDK_INT;      if (sdkInt >= Build.VERSION_CODES.LOLLIPOP) {         setTranslucentStatusBarLollipop(window);      } else if (sdkInt >= Build.VERSION_CODES.KITKAT) {         setTranslucentStatusBarKiKat(window);      }   }  @TargetApi(Build.VERSION_CODES.LOLLIPOP)   private static void setTranslucentStatusBarLollipop(Window window) {      window.setStatusBarColor(             window.getContext()                   .getResources()                   .getColor(R.color. / add here your translucent color code /));   }   @TargetApi(Build.VERSION_CODES.KITKAT)   private static void setTranslucentStatusBarKiKat(Window window) {      window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);   }