title: Go edge-to-edge on Android correctly with WindowInsets
body: <p>I'm trying to get edge-to-edge (<a href="https://youtu.be/OCHEjeLC_UY?t=1635" rel="nofollow noreferrer">https://youtu.be/OCHEjeLC_UY?t=1635</a>) working correctly on API 21 up to 29.</p>
  
  <p>I'm using this on my <code>v27\themes.xml</code>:</p>
  
  <pre><code>&lt;item name="android:windowLightNavigationBar"&gt;true&lt;/item&gt;
  &lt;item name="android:navigationBarColor"&gt;@android:color/transparent&lt;/item&gt;
  </code></pre>
  
  <p>And this in my Activity:</p>
  
  <pre><code>override fun onWindowFocusChanged(hasFocus: Boolean) {
      super.onWindowFocusChanged(hasFocus)
  
      if (hasFocus) {
          window.decorView.systemUiVisibility =
              View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
      }
  }
  </code></pre>
  
  <p>Plus, I'm setting <code>android:fitsSystemWindows=true</code> on my <code>AppBarLayout</code>.</p>
  
  <hr>
  
  <p>With that in place, it looks fine on API >= 27 where the content scrolls behind the now transparent navigation bar but on older APIs, the content is covered by the black navigation bar.</p>
  
  <p>I know that I need to get the <code>WindowInsets</code> and add it to my existing padding (or in case of <code>AppBarLayout</code> it will handle the insets itself), but I cannot get it to work with a FAB.</p>
  
  <p>I found <a href="https://medium.com/androiddevelopers/windowinsets-listeners-to-layouts-8f9ccc8fa4d1" rel="nofollow noreferrer">this article</a> about adding the inset to the <code>padding</code> of a view but because the FAB uses <code>margin</code> I'm not sure, if I'm on the right track.</p>
  
  <hr>
  
  <p>Is there any documentation, example, best practice on how to handle insets when going edge-to-edge? It seems that some widgets like <code>AppBarLayout</code> handle it gracefully but how can I get the FAB to adjust its margin as well?</p>
  
  <hr>
  
  <h3>Update 1</h3>
  
  <p>To specify, when adding <code>android:fitsSystemWindows=true</code> to <code>CoordinatorLayout</code> it handles the insets as well but with a major drawback:</p>
  
  <p>I have two layouts, each with a <code>CoordinatorLayout</code>: "parent layout" defines a <code>CoordinatorLayout</code> with a <code>AppBarLayout</code> and a <code>FrameLayout</code> to hold the actual content and "child layout" used by a Fragment placed in the latter.</p>
  
  <p>Because of this, I cannot add <code>android:fitsSystemWindows=true</code> to the child layout because it would result in a blank space on top (between the toolbar and the content) and I cannot put it in the parent layout because then the FAB won't be updated to the insets.</p>