ListView top highlight on scrolling
Asked Answered
S

6

20

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

Spiderwort answered 15/10, 2011 at 12:23 Comment(6)
developer.android.com/resources/articles/…Chronometry
set android:cacheColorHine="#676767" in list viewResurrectionist
it's not android:cacheColorHine problem. android:cacheColorHine is already transparent. The problem is in this orange line, which is APPEAR ONLY WHEN YOU SCROLL at the end of the list view. See, you are already on the end (or start) of the list view and you continue scrolling bottom (or up). but its not scrolling cos we are already at the end (or at the top) of the list, and this orange line appearSpiderwort
People I think this highlight only in Nexus S modelSpiderwort
Yes, I did. Its in @louiscoquio's postSpiderwort
@Bhuro, the link in your answer has been moved to android-developers.blogspot.com/2009/01/… . Hope this helps people.Enaenable
F
47

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

Foreignism answered 27/3, 2012 at 8:49 Comment(4)
Oh yes, thank you, I didn't see it because of its since API Level 9Spiderwort
I tried its not working nothing changes i can still see the blue api 17Bloke
Worked for me. I'm on API 21.Capsular
Of course, other carriers (non-nexus) love to override this kind of thing.Capsular
T
7

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.

Tobietobin answered 10/7, 2013 at 11:54 Comment(3)
Wow. This is great answer. How could this has not been noticed yet. Really you are genius. Thanks a lot!Oquassa
This stopped working in Lollipop. See my answer below: https://mcmap.net/q/501424/-listview-top-highlight-on-scrollingBugleweed
Not worked for me. I took a class extending ListView and override onOverScrolled(), then called removeOverScrollEffect() from onOverScrolled(). But with no effect.Saury
A
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"

Acceptor answered 16/10, 2011 at 5:45 Comment(1)
Hi, The question is not about cacheColor. It is about the changing colour for overScrollMode effect.Saury
B
3

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

Bookstack answered 28/3, 2012 at 4:57 Comment(3)
thank you!!!, the fadingEdge is not work well with if i have padding and clipToPadding falseFauna
@Shawn Thye: my answer was very old as some new API has been updated. Check my edited answer.Bookstack
haha, your are right, but I only need to disable it on low api deviceFauna
B
2

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

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

    Field field = superClass.getDeclaredField("mEdgeGlowTop");
    field.setAccessible(true);
    field.set(this, new NoEdgeEffect(getContext()));

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

class NoEdgeEffect extends EdgeEffect
{
    public NoEdgeEffect(Context context) {
        super(context);
    }
    public boolean draw(Canvas canvas) {
        // Do nothing
        return false;
    }
}
Bugleweed answered 3/8, 2015 at 11:30 Comment(1)
This answer is just to hide overScroll effect. For doing that, you can use only 1 line: android:overScrollMode="never"Saury
S
0

you can use android:listSelector="#002234".

In above value can be any color code that you can find on internet easily.

Sororate answered 15/10, 2011 at 12:30 Comment(8)
no, it's not that. It changes color when you press on list view, but not color that appears when you rich end of the list viewSpiderwort
reach at the end means? what you want exactly i didnot get you i think ?Sororate
Do you see this orange line? It APPEARS ONLY WHEN YOU SCROLL at the end of the list view. See, you are already on the end (or start) of the list view and you continue scrolling bottom (or up). but its not scrolling cos we are already at the end (or at the top) of the list, and this orange line appearSpiderwort
then try to use android:cacheColorHint="#00000000".Tell me if it is working.This is for other purpose but it may work.just try it.Sororate
yes, I set it before (there was black cover with background on scroll), and it hide problem with background, but not this orange lineSpiderwort
@Pleerock Have you find any solution for this issue?Pacifa
@AndroEmbedded the solution is in the louiscoquio answerSpiderwort
this will change the List Item background color on its selection, not the overscroll highlight color of the list view.Canonicals

© 2022 - 2024 — McMap. All rights reserved.