Trong định nghĩa XML ListView của bạn, thêm
android:fastScrollEnabled="true"
hoặc trong mã
listView.setFastScrollEnabled(true);
Tạo tập tin fastscroll_thumb.xml trong res/thư mục drawable như sau:
<?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>
Trong AndroidManifest.xml, thiết lập một chủ đề tùy chỉnh cho ứng dụng của bạn:
<application
android:theme="@style/ApplicationTheme"
...>
Tạo một thư mục các giá trị trong thư mục res. Tạo themes.xml file trong res/values như sau:
<resources>
<style name="ApplicationTheme">
<item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb</item>
</style>
</resources>
Cuối cùng chắc chắn rằng fastscroll.png và fastscroll_pressed.png tồn tại trong thư mục drawable của bạn
(không bắt buộc) Bạn cũng có thể thiết lập nhanh chóng di chuyển luôn có thể nhìn thấy trong khi bạn đang gỡ lỗi nếu bạn thích
listView.setFastScrollAlwaysVisible(true);
hoặc trong XML
android:fastScrollAlwaysVisible="true"
coi chừng 'listView.setFastScrollAlwaysVisible' vì nó chỉ đến từ cấp API 11 –