您可以设置一些反射的EdgeEffect
颜色:ViewPager
public static void setEdgeGlowColor(ViewPager viewPager, int color) {
try {
Class<?> clazz = ViewPager.class;
for (String name : new String[] {
"mLeftEdge", "mRightEdge"
}) {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
Object edge = field.get(viewPager); // android.support.v4.widget.EdgeEffectCompat
Field fEdgeEffect = edge.getClass().getDeclaredField("mEdgeEffect");
fEdgeEffect.setAccessible(true);
setEdgeEffectColor((EdgeEffect) fEdgeEffect.get(edge), color);
}
} catch (Exception ignored) {
}
}
public static void setEdgeEffectColor(EdgeEffect edgeEffect, int color) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
edgeEffect.setColor(color);
return;
}
Field edgeField = EdgeEffect.class.getDeclaredField("mEdge");
Field glowField = EdgeEffect.class.getDeclaredField("mGlow");
edgeField.setAccessible(true);
glowField.setAccessible(true);
Drawable mEdge = (Drawable) edgeField.get(edgeEffect);
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 (Exception ignored) {
}
}