Custom Listview Fast Scrollbar in android

后端 未结 2 1600
你的背包
你的背包 2020-12-01 02:41

I want to custom a listview with a touchable fast scrollbar like Google play music app with vertical line with thumb image. It provides an easy and fast way to scroll with t

2条回答
  •  鱼传尺愫
    2020-12-01 03:00

    so for android api level < 11 there is special hack

    // special hack for violet fast scroll
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
                try {
                    java.lang.reflect.Field f = AbsListView.class.getDeclaredField("mFastScroller");
                    f.setAccessible(true);
                    Object o = f.get(root.findViewById(R.id.beam_contact_listview));
                    f = f.getType().getDeclaredField("mThumbDrawable");
                    f.setAccessible(true);
                    Drawable drawable = (Drawable) f.get(o);
                    drawable = getResources().getDrawable(R.drawable.sv_fastscroll);
                    f.set(o, drawable);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
    

    this code plus solution for android api level >= 11 = solution for all android api levels )

提交回复
热议问题