title: How does the Android L contacts app collapse its toolbar?
body: <p>I've been trying to reproduce the way that the Contacts app on version 5.0 collapses the toolbar when the listview is scrolled.</p>
  
  <p><a href="https://imgur.com/a/51fnA" rel="noreferrer">Gallery of screenshots demonstrating the desired interaction</a>
  Note the collapse of the toolbar in stages, where it displays search+last contact, fades last contact, collapses last contact, collapses search, leaving only the tabs.</p>
  
  <p>So far, I have a toolbar sitting above a recyclerview in a LinearLayout, and the toolbar is used as an actionbar, not standalone.</p>
  
  <p>I can't figure out how to intercept the touch event on the recyclerview and make it shrink the toolbar, and then return the scroll event to the recyclerview. I tried putting the entire thing in a scrollview, but then the recyclerview couldn't calculate it's height properly and displayed no content. I tried overriding onscroll on the recyclerview, and found that it will only notify me when a scroll event started, and provide me with the first visible card id. </p>
  
  <p>The way that looks right, but I can't get working for the life of me, is this:</p>
  
  <pre><code>getSupportActionBar().setHideOnContentScrollEnabled(true);
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code> Caused by: java.lang.UnsupportedOperationException: Hide on content scroll is not supported in this action bar configuration.
  </code></pre>
  
  <p>Using a traditional actionbar, putting a toolbar below it, and setting hideoncontentscrollenabled also didn't work, scrolling never triggered the hide method on the actionbar.</p>
  
  <p>-- edit --
  I was able to get hideOnContentScrollEnabled working on a listview with a traditional actionbar, but the behavior is not the same as the contacts app. This is clearly not the method they used-- it simply triggers .hide() on the actionbar when a fling event occurs on a listview, which is notably different from the contacts app, which drags the toolbar along with the scroll event.
  -- /edit --</p>
  
  <p>So I abandoned that route, and put fill_parent on the cardview height, and animated a collapse on the toolbar. But how do I trigger it so that it follows the touch event and then returns the touch event to the recyclerview?</p>
  
  <p><em>activity_main.xml</em></p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      &gt;
  
      &lt;android.support.v7.widget.Toolbar
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:minHeight="?android:attr/actionBarSize"
          android:background="@color/colorPrimary"
          /&gt;
  
      &lt;fragment android:name="me.myapplication.FragmentTab"
            android:id="@+id/tab_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><em>fragment_layout.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center_horizontal"
      android:orientation="vertical"
      android:padding="8dp"
      android:background="#eeeeee"
      &gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recycler_view"
          android:layout_width="match_parent"
          android:layout_height="fill_parent"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><em>styles.xml</em></p>
  
  <pre><code>...
  &lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;
  ...
  </code></pre>
  
  <p><em>MainActivity.java</em></p>
  
  <pre><code>Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
  
  // Disable the logo in the actionbar, as per material guidelines
  toolbar.getMenu().clear();
  toolbar.setTitle("My toolbar");
  setSupportActionBar(toolbar);
  </code></pre>