5

I am currently trying to change the color of the blue horizontal line that appears when you reach the top or bottom of a scrollview. I tried to dig within the Android res folder but could not find any obvious reference to it.

Any help would be much appreciated.

Thank you.

Update: After having tried to implement a class inheriting ScrollView and settings getSolidColor to an alternative value, it does not seem to work. The horizontal bar that appears when I reach the bottom or top of the scrollview is still in blue.

Update 2: Actually, I should not have mentioned the edge effect color, it was more specifically the overScroll effect, but I was not aware of that term.

Moystard
  • 1,827
  • 2
  • 17
  • 18

7 Answers7

8

I found a partial answer to my question, I was actually referring to the overscroll attribute of the ScrollView. It seems to be possible to disable it using the code below:

<ScrollView
...
android:overScrollMode="never"
... />

However, it is impossible to modify the color using the overScrollHeader and overScrollFooter attributes as their values are just ignored and the default blue one is shown instead.

Moystard
  • 1,827
  • 2
  • 17
  • 18
5

You can use the Edge Effect Override Library to dynamically override the color of the glowing edges on scroll views. It is pretty simple to use and can add a little uniqueness to your apps. Find it here: https://github.com/AndroidAlliance/EdgeEffectOverride

George
  • 81
  • 1
  • 5
3

You can change the EdgeEffect color of a ScrollView with some reflection:

public static void setEdgeGlowColor(final ScrollView scrollView, final int color) {
    try {
        final Class<?> clazz = ScrollView.class;
        final Field fEdgeGlowTop = clazz.getDeclaredField("mEdgeGlowTop");
        final Field fEdgeGlowBottom = clazz.getDeclaredField("mEdgeGlowBottom");
        fEdgeGlowTop.setAccessible(true);
        fEdgeGlowBottom.setAccessible(true);
        setEdgeEffectColor((EdgeEffect) fEdgeGlowTop.get(scrollView), color);
        setEdgeEffectColor((EdgeEffect) fEdgeGlowBottom.get(scrollView), color);
    } catch (final Exception ignored) {
    }
}

@SuppressLint("NewApi")
public static void setEdgeEffectColor(final EdgeEffect edgeEffect, final int color) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            edgeEffect.setColor(color);
            return;
        }
        final Field edgeField = EdgeEffect.class.getDeclaredField("mEdge");
        final Field glowField = EdgeEffect.class.getDeclaredField("mGlow");
        edgeField.setAccessible(true);
        glowField.setAccessible(true);
        final Drawable mEdge = (Drawable) edgeField.get(edgeEffect);
        final Drawable mGlow = (Drawable) glowField.get(edgeEffect);
        mEdge.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        mGlow.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        mEdge.setCallback(null); // free up any references
        mGlow.setCallback(null); // free up any references
    } catch (final Exception ignored) {
    }
}
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
2

I found a very simple (but hackish) way to accomplish this (changing the color of the glow):

int glowDrawableId = context.getResources().getIdentifier("overscroll_glow", "drawable", "android");
Drawable androidGlow = context.getResources().getDrawable(glowDrawableId);
androidGlow.setColorFilter(brandColor, PorterDuff.Mode.MULTIPLY);

I took advantage of the fact that the glow effect is actually a Drawable (and un-mutate at that), and applied a filter on it. More about it, here: http://evendanan.net/android/branding/2013/12/09/branding-edge-effect/

Menny
  • 473
  • 6
  • 13
  • Great. But apart from the glow light there's a line which appears above(when sliding up) and below(when sliding down). Do you know how to change it's color too? – WWJD Sep 12 '14 at 11:20
1

There doesn't seem to be an easy way to do this using the api. You could however try extending ScrollView and overriding the getSolidColor() method, setting the background to a different color:

    new ScrollView(this) {
        @Override
        @ExportedProperty(category = "drawing")
        public int getSolidColor() {
            // Set a background color to a color you want for the edges.
        }
    };
Community
  • 1
  • 1
Jeshurun
  • 22,940
  • 6
  • 79
  • 92
  • I will try that and give you a feedback. Weird that you cannot easily do that, as this blue does not fit most application themes. – Moystard Jul 22 '12 at 19:34
  • Done, and it does not seem to work, the blue horizontal bar is still blue. – Moystard Jul 22 '12 at 20:45
1

If you want the same color for the fading edge and for the ScrollView's background, you can just add :

<ScrollView
...
android:background="@color/yourColor"
... />

If you want the edge to be a different color then you have to extend ScrollView and override the getSolidColor() method.

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
0

This is the way you change the overscroll edge line:

        final int edgeDrawableId = res.getIdentifier("overscroll_edge", "drawable", "android");
        final Drawable overscrollEdge = res.getDrawable(edgeDrawableId);
        overscrollEdge.setColorFilter(res.getColor(colorID), android.graphics.PorterDuff.Mode.SRC_ATOP);
bapho
  • 858
  • 8
  • 13