Scrollbar color in RecyclerView

Yass picture Yass · Feb 15, 2016 · Viewed 18.6k times · Source

How can I change the color of my scrollbar in a recyclerView?

I have the scrollbar but I want to change its color. My recyclerView is like this:

 <android.support.v7.widget.RecyclerView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:id="@+id/recyclerView"
   android:layout_below="@id/my_toolbar"
   android:layout_above="@+id/progressBar"
   android:scrollbars="vertical"
   />

Answer

Naresh picture Naresh · Feb 15, 2016

You can do this by including following line of code in your Recyclerview

android:scrollbarThumbVertical="@drawable/yoursdrawablefile

The drawable file in my case is:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#000" android:endColor="#000"
        android:angle="45"/>
    <corners android:radius="6dp" />
</shape>