Skip to content Skip to sidebar Skip to footer

Listview Top Highlight On Scrolling

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 loo

Solution 1:

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

You can also set it directly in the XML :

<ListViewandroid: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

Solution 2:

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:

@OverrideprotectedvoidonOverScrolled(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.
}

privatevoidremoveOverscrollEffect() {
    try {
        Class<?> superClass = getClass().getSuperclass().getSuperclass();

        Fieldfield= superClass.getDeclaredField("mEdgeGlowTop");
        field.setAccessible(true);
        ObjectedgeGlowTop= field.get(this);
        if (edgeGlowTop != null) {
            Class<? extendsObject> edgeClass = edgeGlowTop.getClass();
            FieldedgeDrawable= edgeClass.getDeclaredField("mEdge");
            edgeDrawable.setAccessible(true);
            edgeDrawable.set(edgeGlowTop, newColorDrawable(Color.TRANSPARENT));
            FieldglowDrawable= edgeClass.getDeclaredField("mGlow");
            glowDrawable.setAccessible(true);
            glowDrawable.set(edgeGlowTop, newColorDrawable(Color.TRANSPARENT));
            field.set(this, edgeGlowTop);
        }

        FieldfieldBottom= superClass.getDeclaredField("mEdgeGlowBottom");
        fieldBottom.setAccessible(true);
        ObjectedgeGlowBottom= fieldBottom.get(this);
        if (edgeGlowBottom != null) {
            Class<? extendsObject> edgeClassBottom = edgeGlowBottom.getClass();
            FieldedgeDrawableBottom= edgeClassBottom.getDeclaredField("mEdge");
            edgeDrawableBottom.setAccessible(true);
            edgeDrawableBottom.set(edgeGlowBottom, newColorDrawable(Color.TRANSPARENT));
            FieldglowDrawableBottom= edgeClassBottom.getDeclaredField("mGlow");
            glowDrawableBottom.setAccessible(true);
            glowDrawableBottom.set(edgeGlowBottom, newColorDrawable(Color.TRANSPARENT));
            fieldBottom.set(this, edgeGlowBottom);
        }
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}

I hope this helps.

Solution 3:

Here is a nice article on ListView Backgrounds Optimization.

To fix this issue, all you have to do is either disable the cache color hint optimization, if you use a non-solid color background, or set the hint to the appropriate solid color value. You can do this from code (see setCacheColorHint(int)) or preferably from XML, by using the android:cacheColorHint attribute. To disable the optimization, simply use the transparent color #00000000. The following screenshot shows a list with android:cacheColorHint="#00000000"

Solution 4:

Use it in XML file--

<ListView ---
     android:fadingEdge="none"---</ListView>

EDITED:

Using fading edges may introduce noticeable performance degradations and should be used only when required by the application's visual design. To request fading edges with API level 14 and above, use the android:requiresFadingEdge attribute instead.

Check this API link

Solution 5:

I used kord's answer until it stopped working in Lollipop, so I changed into this:

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

    Fieldfield= superClass.getDeclaredField("mEdgeGlowTop");
    field.setAccessible(true);
    field.set(this, newNoEdgeEffect(getContext()));

    FieldfieldBottom= superClass.getDeclaredField("mEdgeGlowBottom");
    fieldBottom.setAccessible(true);
    fieldBottom.set(this, newNoEdgeEffect(getContext()));
} catch (Exception e) {
}

classNoEdgeEffectextendsEdgeEffect
{
    publicNoEdgeEffect(Context context) {
        super(context);
    }
    publicbooleandraw(Canvas canvas) {
        // Do nothingreturnfalse;
    }
}

Post a Comment for "Listview Top Highlight On Scrolling"