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.
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.
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
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) {
}
}
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With