title: CoordinatorLayout as top-level decor when NavHostFragment contains non-scrolling views
body: <p>I'm attempting to make a single-activity app with shared chrome (toolbar, etc) in the activity.</p>
  
  <p>I'd like to use Google's components (<code>CoordinatorLayout</code> and <code>AppBarLayout</code>) to make use of the toolbar's auto-hide feature, which hides/reveals when content is scrolled. This is crucial for the "home" destination of the app which has a view pager with scrollable content on each page.</p>
  
  <p>I've set the <code>NavHostFragment</code>'s <code>layout_behavior</code> to the suggested scrolling behavior, but this doesn't work well when a non-scrolling fragment is occupying the <code>NavHostFragment</code>. In such a case, the content of the fragment is pushed down (cutting off the bottom portion) to make room for the toolbar in the activity layout.</p>
  
  <p><strong>Activity layout:</strong></p>
  
  <pre><code>&lt;androidx.coordinatorlayout.widget.CoordinatorLayout
      android:id="@+id/coordinator_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;com.google.android.material.appbar.AppBarLayout
          android:id="@+id/app_bar_layout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:elevation="0dp"&gt;
  
          &lt;com.google.android.material.appbar.MaterialToolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:layout_scrollFlags="scroll|snap|enterAlways"/&gt;
  
      &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
      &lt;fragment
          android:id="@+id/nav_host_main"
          android:name="androidx.navigation.fragment.NavHostFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:defaultNavHost="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          app:navGraph="@navigation/nav_graph_main"/&gt;
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>The home destination with scrolling content (<code>ViewPager2</code> with a <code>RecyclerView</code> on each page) works as intended. The toolbar hides/reveals as expected.</p>
  
  <p>However, when I navigate to another destination that doesn't have scrolling content (it's just a <code>ConstraintLayout</code> with height set to <code>match_parent</code> and child views anchored to the bottom and top of the layout), the content is cut off at the bottom.</p>
  
  <p>Adding bottom padding to the non-scrolling destination isn't an option because the shared toolbar can expand upon entering this destination (as it may have been collapsed in the previous destination) and just pushes the content down as it animates.</p>
  
  <p>The problem I'm seeing is that the <code>NavHostFragment</code> is positioned below the toolbar, rather than behind it (due to the scrolling view behavior).</p>
  
  <p>I'm not sure what to do. Wrapping my head around this while also worrying about window insets is a pain in the neck. I'm considering just abandoning the <code>CoordinatorLayout</code> as shared chrome and adding it only to the destinations that have scrolling content. It would limit what animations I can use between destinations, but that seems to be the best option at this point.</p>
  
  <p>Any thoughts?</p>