首页 > 代码库 > 修改listview默认的滑动条

修改listview默认的滑动条

首先把布局文件中李斯特view添加android:fastScrollEnabled="true";

然后代码中添加代码:

private void setScrollBar()
{
try
{
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(listview);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.ic_launcher);
f.set(o, drawable);
} catch (Exception e)
{
throw new RuntimeException(e);
}


}