title: Appbar fitsSystemWindows - Inside a ViewPager
body: <p>I have an Activity that contains a <code>ViewPager</code>:</p>
  
  <blockquote>
    <p><code>activity.xml:</code></p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/pager"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fitsSystemWindows="true"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  </blockquote>
  
  <p>The fragments this pager contains – which are all generated from the same layout – have a <code>CoordinatorLayout</code> and <code>CollapsingToolbarLayout</code> to provide a collapsing image-back titlebar:</p>
  
  <blockquote>
    <p><code>fragment.xml:</code></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"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/coordinator_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"&gt;
  
      &lt;android.support.v4.widget.NestedScrollView
          android:id="@+id/scrollview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
          &lt;!-- Content here --&gt;
  
      &lt;/android.support.v4.widget.NestedScrollView&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/appbar"
          android:layout_width="match_parent"
          android:layout_height="256dp"
          android:elevation="8dp"
          android:fitsSystemWindows="true"&gt;
  
          &lt;android.support.design.widget.CollapsingToolbarLayout
              android:id="@+id/collapsing_toolbar"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layout_scrollFlags="scroll|exitUntilCollapsed"
              app:expandedTitleMarginStart="72dp"
              android:fitsSystemWindows="true"&gt;
  
              &lt;ImageView
                  android:id="@+id/photo"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:scaleType="centerCrop"
                  app:layout_collapseMode="parallax"
                  android:background="@color/photo_placeholder"
                  android:fitsSystemWindows="true"/&gt;
  
              &lt;android.support.v7.widget.Toolbar
                  android:id="@+id/toolbar"
                  android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                  android:layout_width="match_parent"
                  android:layout_height="?actionBarSize"
                  app:layout_collapseMode="pin"
                  android:layout_gravity="bottom"&gt;
  
              &lt;/android.support.v7.widget.Toolbar&gt;
  
          &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  </blockquote>
  
  <p>Without the <code>fitsSystemWindows</code> flags in the activity layout, the image in the fragment properly displays behind the system status bar, while the text sometimes collapses behind the status bar when scrolled up. If I add the flags in – as shown above – the text issue is resolved, but the image now cuts off at the status bar. Keeping the collapsing toolbar code in the fragment, is there a way to fit the fragment's content to the system window?</p>
  
  <p>Without <code>fitsSystemWindows</code> in the activity (preferred behaviour):
  <a href="https://i.stack.imgur.com/JJLE0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JJLE0.png" alt="Without fitsSystemWindows"></a></p>
  
  <p>With <code>fitsSystemWindows</code> in the activity:
  <a href="https://i.stack.imgur.com/jd5Lf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jd5Lf.png" alt="enter image description here"></a></p>