ListView之快速滑块

来源:互联网 发布:海尔洗衣机 知乎 编辑:程序博客网 时间:2024/04/29 07:50
          //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();        }
0 0