2011-08-14 33 views

回答

10

在你的ListView XML定義,添加

android:fastScrollEnabled="true" 

或代碼

listView.setFastScrollEnabled(true); 

在res /可繪製文件夾中創建文件fastscroll_thumb.xml如下:

<?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> 

在AndroidManifest.xml中,爲您的應用程序自定義主題:

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

創建res文件夾一個文件夾值。創建RES /值的themes.xml文件內容如下:

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

最後確保fastscroll.png和fastscroll_pressed.png在繪製文件夾

(可選)存在 您還可以設置快速滾動始終可見,而你正在調試,如果你喜歡

listView.setFastScrollAlwaysVisible(true); 

或XML

android:fastScrollAlwaysVisible="true" 
+1

因爲它只來自API級別11,所以要提防'listView.setFastScrollAlwaysVisible' –

相關問題