Is it possible to change the color or appearance of the scrollbar in a ScrollView or ListView?
Asked
Active
Viewed 4.0k times
2 Answers
85
You can set Listview property as
android:scrollbarSize="10dp"
android:scrollbarThumbVertical="@drawable/custom_scroll_style"
Here custom_scroll_style is a xml file under the drawable folder. Lets create the custom_scroll_style.xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#FF3401"
android:centerColor="#ff5c33"
android:startColor="#FF3401" />
<corners android:radius="8dp" />
<size android:width="4dp"/>
<padding
android:left="0.5dp"
android:right="0.5dp" />
</shape>
Here I got a Orange color scrollbar. You can use images also if the image size is less than 2px instead of xml.

tomrozb
- 25,773
- 31
- 101
- 122

Silambarasan Poonguti
- 9,386
- 4
- 45
- 38
-
4Use `@color/` for color. Example: `@color/white` Otherwise it's a great answer. – Secko Aug 15 '14 at 18:21
-
1Which directory should I put `custom_scroll_style.xml` in? Drawables? Styles? – the_prole Dec 25 '15 at 20:11
-
you should add it in drawable folder. if it not exist create folder called drawable under resources(res) directory and add custom_scroll_style in it. – Silambarasan Poonguti Dec 26 '15 at 05:58
37
Check out the ApiDemos sample project in the SDK. The layout res/layout/scrollbar2.xml
shows a way to style scroll bars.
There are separate attributes for the scrollbar track and the scrollbar thumb. Size can also be adjusted.

adamp
- 28,862
- 9
- 81
- 69
-
23Good sir, I salute you! For other people searching the same answer: Just do android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb" and let scrollbar_vertical_thumb be a gradient :) – pgsandstrom Jun 21 '10 at 07:56
-
18
-
-