title: How to support full screen navigation UI for RecyclerView?
body: <h2>Background</h2>
  
  <p>I wanted to support full screen navigation UI as shown here:</p>
  
  <p><a href="https://medium.com/androiddevelopers/windowinsets-listeners-to-layouts-8f9ccc8fa4d1" rel="nofollow noreferrer">https://medium.com/androiddevelopers/windowinsets-listeners-to-layouts-8f9ccc8fa4d1</a>
  <a href="https://developer.android.com/guide/navigation/gesturenav" rel="nofollow noreferrer">https://developer.android.com/guide/navigation/gesturenav</a></p>
  
  <h2>The problem</h2>
  
  <p>While all Activities of my app worked fine, I suddently reached a problematic one that has a RecyclerView with thumbs.</p>
  
  <p>Here, I got 2 weird issues:</p>
  
  <ol>
  <li>When scrolling to the bottom, the last item/s don't get fully shown.</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/0XxJF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0XxJF.png" alt="enter image description here"></a></p>
  
  <ol start="2">
  <li>When in landscape mode, the thumbs go outside of anywhere that I can reach, so they are also not touchable. Not only that, but I can also see the normal scrollbar, and both get to disappear when scrolling to the bottom:</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/eESDJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eESDJ.png" alt="enter image description here"></a></p>
  
  <h2>What I've tried</h2>
  
  <p>I tried to apply the insets to various views, including both padding and margins, but nothing helped.</p>
  
  <p>Also, in some websites I saw that I should use <code>View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION</code> and in some that I need to also add <code>View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN</code>. Didn't help.</p>
  
  <p>Here's my current code (project available <a href="https://issuetracker.google.com/issues/143530492" rel="nofollow noreferrer"><strong>here</strong></a>, as I think this is a bug) :</p>
  
  <p><strong>MainActivity.kt</strong></p>
  
  <pre><code>class MainActivity : AppCompatActivity(R.layout.activity_main) {
      inline fun View.updateMargins(@Px left: Int = marginLeft, @Px top: Int = marginTop, @Px right: Int = marginRight, @Px bottom: Int = marginBottom) {
          updateLayoutParams&lt;ViewGroup.MarginLayoutParams&gt; {
              this.bottomMargin = bottom
              this.topMargin = top
              this.leftMargin = left
              this.rightMargin = right
          }
      }
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setSupportActionBar(toolbar)
          findViewById&lt;View&gt;(android.R.id.content).systemUiVisibility =
              View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
          ViewCompat.setOnApplyWindowInsetsListener(appBarLayout) { _, insets -&gt;
              val systemWindowInsets = insets.systemWindowInsets
              appBarLayout.updateMargins(
                  left = systemWindowInsets.left,
                  top = systemWindowInsets.top,
                  right = systemWindowInsets.right
              )
              insets
          }
  
          ViewCompat.setOnApplyWindowInsetsListener(recyclerView) { _, insets -&gt;
              val systemWindowInsets = insets.systemWindowInsets
              recyclerView.updatePadding(
                  left = systemWindowInsets.left,
                  bottom = systemWindowInsets.bottom,
                  right = systemWindowInsets.right
              )
              insets
          }
  
          recyclerView.adapter = object : RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;() {
              init {
                  setHasStableIds(true)
              }
  
              override fun onCreateViewHolder(
                  parent: ViewGroup,
                  viewType: Int
              ): RecyclerView.ViewHolder {
                  return object : RecyclerView.ViewHolder(
                      LayoutInflater.from(this@MainActivity).inflate(R.layout.list_item, parent, false)
                  ) {}
              }
  
              override fun getItemId(position: Int): Long = position.toLong()
  
              override fun getItemCount(): Int = 100
  
              override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
                  holder.itemView.imageView.setColorFilter(if (position % 2 == 0) 0xffff0000.toInt() else 0xff00ff00.toInt())
                  holder.itemView.textView.text = "item $position"
              }
  
          }
      }
  
      override fun onCreateOptionsMenu(menu: Menu): Boolean {
          menu.add("test").setIcon(android.R.drawable.ic_dialog_email).setOnMenuItemClickListener {
              true
          }.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
          return super.onCreateOptionsMenu(menu)
      }
  }
  </code></pre>
  
  <p><strong>styles.xml</strong> (I use AppTheme in the manifest as theme)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;resources xmlns:tools="http://schemas.android.com/tools"&gt;
  
      &lt;style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar"&gt;
          &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
          &lt;item name="android:navigationBarColor" tools:targetApi="lollipop"&gt;
              @android:color/transparent
          &lt;/item&gt;
          &lt;item name="android:statusBarColor" tools:targetApi="lollipop"&gt;@color/colorPrimaryDark
          &lt;/item&gt;
      &lt;/style&gt;
  
      &lt;style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" /&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;androidx.coordinatorlayout.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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"&gt;
  
  
      &lt;com.google.android.material.appbar.AppBarLayout
          android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
          &lt;!--app:popupTheme="@style/AppTheme.PopupOverlay"--&gt;
          &lt;androidx.appcompat.widget.Toolbar
              android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary" /&gt;
      &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
      &lt;androidx.recyclerview.widget.RecyclerView
          android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent"
          android:orientation="vertical" android:scrollbars="vertical" app:fastScrollEnabled="true"
          app:fastScrollHorizontalThumbDrawable="@drawable/thumb_drawable"
          app:fastScrollHorizontalTrackDrawable="@drawable/line_drawable"
          app:fastScrollVerticalThumbDrawable="@drawable/thumb_drawable"
          app:fastScrollVerticalTrackDrawable="@drawable/line_drawable"
          app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
          app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:itemCount="100"
          tools:listitem="@layout/list_item" /&gt;
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p><strong>line.xml</strong></p>
  
  <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt;
  
      &lt;solid android:color="@android:color/darker_gray" /&gt;
  
      &lt;padding
          android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p><strong>line_drawable.xml</strong></p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:drawable="@drawable/line" android:state_pressed="true" /&gt;
  
      &lt;item android:drawable="@drawable/line" /&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p><strong>thumb.xml</strong></p>
  
  <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt;
      &lt;corners
          android:bottomLeftRadius="44dp" android:topLeftRadius="44dp" android:topRightRadius="44dp" /&gt;
      &lt;padding
          android:paddingLeft="22dp" android:paddingRight="22dp" /&gt;
      &lt;solid android:color="@color/colorPrimaryDark" /&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p><strong>thumb_drawable.xml</strong></p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:drawable="@drawable/thumb" android:state_pressed="true" /&gt;
  
      &lt;item android:drawable="@drawable/thumb" /&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <h2>The questions</h2>
  
  <ol>
  <li>Why does it occur?
  It worked fine for various other places...</li>
  <li>How can I make the RecyclerView avoid both these cases, yet allow the navigation bar at the bottom show content of the RecyclerView as it is transparent?</li>
  <li>In which cases should I add the flag <code>View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN</code>? What does it do to help in these cases?</li>
  </ol>
  
  <hr>
  
  <p>EDIT: a possible workaround is to avoid using CoordinatorLayout. It works well, but I wanted to do things "the official way". Here's this workaround:</p>
  
  <p>Instead of CoordinatorLayout I used :</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
      xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"&gt;
  </code></pre>
  
  <p>...</p>
  
  <p>And in code, I've set both margins and padding to the RecyclerView:</p>
  
  <pre><code>    ViewCompat.setOnApplyWindowInsetsListener(recyclerView) { _, insets -&gt;
          val systemWindowInsets = insets.systemWindowInsets
          recyclerView.updatePadding(
              bottom = systemWindowInsets.bottom
          )
          recyclerView.updateMargins(
              left = systemWindowInsets.left,
              right = systemWindowInsets.right
          )
          insets
      }
  </code></pre>