How to create custom style for fast scroll scrollbar in Android

Published by Igor Khrupin on

Here is sample for fastScroll ListView functionality.

To apply this style you need add the following lines into your app’s style:

<item name="android:fastScrollThumbDrawable">@drawable/fastscroll_drawable</item>
        <item name="android:fastScrollOverlayPosition">atThumb</item>
        <item name="android:fastScrollTrackDrawable">@drawable/track_fastscroll</item>

Also if you need handle click action on your scrollbar you need create the next drawable:

<?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_fastscroll_selected"/>
    <item android:drawable="@drawable/thumb_fastscroll"></item>
</selector>

Also you need apply this style in the AndroidManifest.xml or in another way.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hrupin.sample.custonui.fastscroll"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@style/AppTheme">
        <activity
            android:name="com.hrupin.sample.custonui.fastscroll.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Here is screenshots of app:

2014-11-11 18.06.14

2014-11-11 18.06.25

Full source code you can get from github:

Download it from github

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.