//android:fastScrollEnabled属性值设为true,使用java代码需要电泳
listView.setFastScrollEnabled(true);
//ListView组件并没有提供修改快速图像的API,因此不能直接修改快速滑块图像。但可以通过反射技术修改快速滑块图像
try {
//FastScroller.mThumbDrawable变量保存了快速滑块图像,首先要通过AbsListView.mFastScroller变量
//获取FastScroller对象
Field field = AbsListView.class.getDeclaredField("mFastScroller");
field.setAccessible(true);
Object obj = field.get(listView);
//获取FastScroller.mThumbDrawable变量的Field对象
field = field.getType().getDeclaredField("mThumbDrawable");
field.setAccessible(true);
//获取FastScroller.mThumbDrawable变量的值
Drawable drawable = (Drawable)field.get(obj);
//装载新的快速滑块图像
drawable = getResources().getDrawable(R.drawable.common_listview_headview_red_arrow);
//重新设置快速滑块的图像
field.set(obj,drawable);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
ListView之快速滑块
最新推荐文章于 2021-05-27 08:15:16 发布