ScrollView: change the color of the edge effect with Holo

I'm currently trying to change the color of the blue horizontal line that appears when you reach the top or bottom of the scroll. I tried to dig out the Android res folder, but could not find any obvious link to it.

Any help would be greatly appreciated.

Thank.

Update. Having tried to implement a class that inherits ScrollView and getSolidColor settings for an alternative value, it seems like it does not work. The horizontal bar that appears when I get to the bottom or top of the scroll is still in blue.

Update 2: Actually, I should not have mentioned the red effect, it was a more specific overScroll effect, but I did not know this term.

+5
source share
7 answers

I found a partial answer to my question, I really referred to the overscroll attribute of the ScrollView. It seems that this can be disabled using the following code:

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

However, it is not possible to change the color using the overScrollHeader and overScrollFooter attributes, as their values ​​are simply ignored and blue is displayed instead.

+8
source

You can use the edge effect override library to dynamically redefine the color of luminous edges in scrollable views. It is fairly easy to use and can add a little uniqueness to your applications. Find it here: https://github.com/AndroidAlliance/EdgeEffectOverride

+5
source

EdgeEffect a ScrollView :

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) {
    }
}
+3

( ) ( ):

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

, Drawable ( ) . : http://evendanan.net/android/branding/2013/12/09/branding-edge-effect/

+2

, api. ScrollView getSolidColor(), :

    new ScrollView(this) {
        @Override
        @ExportedProperty(category = "drawing")
        public int getSolidColor() {
            // Set a background color to a color you want for the edges.
        }
    };
+1

ScrollView, :

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

, , ScrollView getSolidColor().

+1
source

This way you change the line of cross-edges:

        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);
0
source

All Articles