Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView top highlight on scrolling

Tags:

The border displays a default color (that's orange on my Nexus S) while scrolling a ListView to the limit. How to change that color?

I really don't know how to explain it. Just look at this picture:

android list view top highlight on scrolling

So, how to change the highlight color when the ListView scrolling to the border? using themes or styles

like image 795
pleerock Avatar asked Oct 15 '11 12:10

pleerock


2 Answers

The solution is to use setOverscrollFooter(null) and setOverscrollHeader(null). The documentation is here !

You can also set it directly in the XML :

<ListView android:overScrollMode="never" />

Or specify the footer and the header :

<ListView 
  android:overscrollHeader="@null" 
  android:overscrollFooter="@null" />

N.B. : There is also a property fadingEdge that may interest you.

"Overscroll" methodes are supported starting API level 9

like image 99
louiscoquio Avatar answered Sep 29 '22 03:09

louiscoquio


Finally I found the solution.

  1. setOverscrollFooter(null) and setOverscrollHeader(null) does not work. At least on 2.3.*. Setting attributes from *.xml doesn't help too.
  2. setOverScrollMode(View.OVER_SCROLL_NEVER) causes glitchy scrolling. At least on 2.3.*.

The only solution that really works involves the use of Java Reflection. It works even with ugly custom Samsung listviews with bounce overscroll effect. Here is a snippet:

@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
    //onOverScrolled method must be overrided, or we will see the background of the listview when overscroll fast.
}

private void removeOverscrollEffect() {
    try {
        Class<?> superClass = getClass().getSuperclass().getSuperclass();

        Field field = superClass.getDeclaredField("mEdgeGlowTop");
        field.setAccessible(true);
        Object edgeGlowTop = field.get(this);
        if (edgeGlowTop != null) {
            Class<? extends Object> edgeClass = edgeGlowTop.getClass();
            Field edgeDrawable = edgeClass.getDeclaredField("mEdge");
            edgeDrawable.setAccessible(true);
            edgeDrawable.set(edgeGlowTop, new ColorDrawable(Color.TRANSPARENT));
            Field glowDrawable = edgeClass.getDeclaredField("mGlow");
            glowDrawable.setAccessible(true);
            glowDrawable.set(edgeGlowTop, new ColorDrawable(Color.TRANSPARENT));
            field.set(this, edgeGlowTop);
        }

        Field fieldBottom = superClass.getDeclaredField("mEdgeGlowBottom");
        fieldBottom.setAccessible(true);
        Object edgeGlowBottom = fieldBottom.get(this);
        if (edgeGlowBottom != null) {
            Class<? extends Object> edgeClassBottom = edgeGlowBottom.getClass();
            Field edgeDrawableBottom = edgeClassBottom.getDeclaredField("mEdge");
            edgeDrawableBottom.setAccessible(true);
            edgeDrawableBottom.set(edgeGlowBottom, new ColorDrawable(Color.TRANSPARENT));
            Field glowDrawableBottom = edgeClassBottom.getDeclaredField("mGlow");
            glowDrawableBottom.setAccessible(true);
            glowDrawableBottom.set(edgeGlowBottom, new ColorDrawable(Color.TRANSPARENT));
            fieldBottom.set(this, edgeGlowBottom);
        }
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}

I hope this helps.

like image 42
kord Avatar answered Sep 29 '22 02:09

kord