«

定制Android ListView 快速滚动的滚动条-fast scroll bar thumb

时间:2024-3-2 19:53     作者:韩俊     分类: Android


1.方法一:

private void initScrollBar() {
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(mListView);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.music_slider);
f.set(o, drawable);
} catch (Exception e) {
e.printStackTrace();
}

}</pre>

方法二:

在style.xml中定义主题

 <style name="audiotheme" parent="android:Theme">
        <item name="android:fastScrollTrackDrawable">@drawable/music_scroll_slider_background</item>
        <item name="android:fastScrollThumbDrawable">@drawable/music_slider</item>
    </style>

在AndroidManifest.xml中应用

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/audiotheme" >


标签: android

热门推荐