title: Translucent/Transparent status bar + CoordinatorLayout + Toolbar + Fragment
body: <p>I have following setup:</p>
  
  <ul>
  <li>I'm using AppCompat</li>
  <li>MainActivity, that holds a fragment and has a toolbar, that's hiding when scrolling down</li>
  <li><code>Fragment</code> with <code>RecyclerView</code></li>
  <li>all views that should fit the screen have the according <code>android:fitsSystemWindows="true"</code> in the xml layout</li>
  </ul>
  
  <p>The problem is, I can't get the statusbar transparent in this case. What I do is following:</p>
  
  <ol>
  <li>Create the activity and call setContent</li>
  <li><p>Then I try to adjust the activity to programmatically get a translucent toolbar like following:</p>
  
  <pre><code>@TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public void themeNavAndStatusBar(Activity activity)
  {
      if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.LOLLIPOP)
          return;
  
      Window w = activity.getWindow();
      w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      w.setFlags(
              WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
              WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
      w.setFlags(
              WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
              WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
      w.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent));
  
      w.setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
  }
  </code></pre></li>
  <li><p>Replace the placeholder in the activity (<code>@+id/frame_container</code>) with the fragment</p></li>
  </ol>
  
  <p>The statusbar is solid colored in this case, and the views are not drawn underneath it... Why?</p>
  
  <p><strong>What I want</strong></p>
  
  <p>I want a toolbar, that is scrolled of the screen and hiding completely while the content underneath this toolbar should fitScreen and be drawn behind the transparent nav bar.</p>
  
  <p><strong>Layouts</strong></p>
  
  <p>Here's my main activity:</p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/clMain"
      android:fitsSystemWindows="true"
      android:background="?attr/main_background_color"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/appBarLayout"
          android:fitsSystemWindows="true"
          android:background="@null"
          app:elevation="0dp"
          app:contentInsetLeft="0dp"
          app:contentInsetStart="0dp"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              android:elevation="4dp"
              android:theme="?actionBarThemeStyle"
              app:popupTheme="?actionBarPopupThemeStyle"
              app:layout_scrollFlags="scroll|enterAlways"&gt;
  
              &lt;LinearLayout
                  android:orientation="vertical"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"&gt;
  
                  &lt;LinearLayout
                      android:orientation="horizontal"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"&gt;
  
                      &lt;ImageView
                          android:id="@+id/ivToolbarDataSource"
                          android:layout_gravity="center_vertical"
                          android:layout_marginRight="2dp"
                          android:layout_width="24dp"
                          android:layout_height="24dp" /&gt;
  
                      &lt;TextView
                          android:id="@+id/tvToolbarTitle"
                          style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                          android:theme="?actionBarThemeStyle"
                          android:layout_gravity="center_vertical"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;TextView
                      android:id="@+id/tvToolbarSubTitle"
                      style="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
                      android:theme="?actionBarThemeStyle"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content" /&gt;
  
              &lt;/LinearLayout&gt;
  
  
  
          &lt;/android.support.v7.widget.Toolbar&gt;
  
          &lt;!-- BUG: http://stackoverflow.com/questions/30541409/coordinatorlayoutappbarlayout-does-not-draw-toolbar-properly --&gt;
          &lt;View
              android:layout_width="fill_parent"
              android:layout_height="1dp"/&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;FrameLayout
          android:id="@+id/frame_container"
          android:fitsSystemWindows="true"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior" /&gt;
  
      &lt;android.support.design.widget.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom|right"
          android:layout_margin="32dp"
          android:src="@drawable/ic_local_offer_white_24dp"
          app:backgroundTint="?attr/colorPrimary"
          app:borderWidth="0dp"
          app:fabSize="normal"
          app:rippleColor="?attr/colorPrimaryDark"
          app:layout_anchorGravity="bottom|right|end"
          app:layout_behavior="com.test.classes.ScrollAwareFABBehavior"/&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>And here is my fragment, that will be placed in the main activity:</p>
  
  <pre><code>&lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:fitsSystemWindows="true"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.v4.widget.SwipeRefreshLayout
          android:id="@+id/srlImages"
          android:fitsSystemWindows="true"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;android.support.v7.widget.RecyclerView
              android:id="@+id/rvImages"
              android:fitsSystemWindows="true"
              android:layout_width="match_parent"
              android:layout_height="match_parent" /&gt;
  
      &lt;/android.support.v4.widget.SwipeRefreshLayout&gt;
  
      &lt;TextView
          android:id="@+id/tvEmpty"
          android:gravity="center"
          android:layout_centerInParent="true"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>EDIT - Screenshots</strong></p>
  
  <p>I use a light/dark base theme and theme everything by hand (because the user can select any color as primary/accent color), so don't mind that the toolbar is white (it's the default's theme background color and primary color). I added a black border as well so that you see where the activity ends...</p>
  
  <ul>
  <li>First Screenshot: Shows the toolbar, nothing is scrolled</li>
  <li>Second Screenshot: I just started scrolling => the toolbar now should scroll away</li>
  <li>Third Screenshot: the main content should now scroll underneath the nav bar...</li>
  </ul>
  
  <p>In the end, I'll of course make the toolbar and navbar semi transparent for a better visual effect...</p>
  
  <p><a href="https://i.stack.imgur.com/7isGd.png"><img src="https://i.stack.imgur.com/7isGd.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/n8wYt.png"><img src="https://i.stack.imgur.com/n8wYt.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/IAyIK.png"><img src="https://i.stack.imgur.com/IAyIK.png" alt="enter image description here"></a></p>