开发者

How to show custom thumb when using fastScrollEnabled

开发者 https://www.devze.com 2023-03-28 14:50 出处:网络
I have a listview of countries in non-alphabetic order and started using fastscroll. I would like to display the country-flag when scrolling with fastscroll but it seems like the APIs has the FastScro

I have a listview of countries in non-alphabetic order and started using fastscroll. I would like to display the country-flag when scrolling with fastscroll but it seems like the APIs has the FastScroll class as private so I cannot override it.

Have anyone else implemented a custom fast开发者_Go百科scroll view?

References: http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:fastScrollEnabled


In your ListView XML definition, add

android:fastScrollEnabled="true"

or in code

listView.setFastScrollEnabled(true);

Create file fastscroll_thumb.xml in the res/drawable folder as follows:

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

In AndroidManifest.xml, set a custom theme for your application:

<application
    android:theme="@style/ApplicationTheme"
    ...>

Create a values folder in the res folder. Create themes.xml files in res/values as follows:

<resources>
    <style name="ApplicationTheme">
        <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb</item>
    </style>
</resources>

Lastly make sure that fastscroll.png and fastscroll_pressed.png exist in your drawable folder

(optional) You can also set fast scroll always visible while you are debugging if you like

listView.setFastScrollAlwaysVisible(true);

or in XML

android:fastScrollAlwaysVisible="true"
0

精彩评论

暂无评论...
验证码 换一张
取 消