How to use fastScrollEnabled in RecyclerView?

Viewed 25078

I am new to RecyclerView and I want to implement the fast scroll feature in RecyclerView like google contact application and search on the internet and i found that now Android provide officially New fastScrollEnabled boolean flag for RecyclerView. So my question is can someone provide the sample implementation of it.

Here is the official document from google https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0

4 Answers

For an eye candy scroll bar thumb(round borders) :

   <android.support.v7.widget.RecyclerView
                android:id="@+id/netflixVideoGridView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                app:fastScrollEnabled="true"
                app:fastScrollHorizontalThumbDrawable="@drawable/fast_scroll_thumb"
                app:fastScrollHorizontalTrackDrawable="@drawable/fast_scroll_track"
                app:fastScrollVerticalThumbDrawable="@drawable/fast_scroll_thumb"
                app:fastScrollVerticalTrackDrawable="@drawable/fast_scroll_track"
                 />

fast_scroll_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true"
        android:drawable="@drawable/thumb"/>

    <item
        android:drawable="@drawable/thumb"/>
</selector>

thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners
        android:radius="50dp" />

    <padding
        android:paddingLeft="22dp"
        android:paddingRight="22dp" />

    <solid android:color="@color/colorPrimaryDark" />

    <stroke
        android:width="1dp"
        android:color="#69f0ae" />

</shape>

track.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#80ffffff" />
    <padding
        android:padding="0dp"/>
</shape>

Result:

enter image description here

Related