@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void setEdgeGlowColor(@NonNull EdgeEffectCompat edgeEffect, @ColorInt int color) throws Exception { Field field = EdgeEffectCompat.class.getDeclaredField("mEdgeEffect"); field.setAccessible(true); EdgeEffect effect = (EdgeEffect) field.get(edgeEffect); if (effect != null) effect.setColor(color); }
@TargetApi(21) private static void trySetEdgeEffectColor(ListView view, String fieldName, int color) { try { Field effectField = AbsListView.class.getDeclaredField(fieldName); effectField.setAccessible(true); EdgeEffect effect = (EdgeEffect) effectField.get(view); final int alpha = Color.alpha(effect.getColor()); effect.setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); } catch (NoSuchFieldException e) { // ignored } catch (IllegalAccessException e) { // ignored } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static void setEdgeGlowColor(@NonNull ScrollView scrollView, @ColorInt int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { Field edgeGlowTop = ScrollView.class.getDeclaredField("mEdgeGlowTop"); edgeGlowTop.setAccessible(true); Field edgeGlowBottom = ScrollView.class.getDeclaredField("mEdgeGlowBottom"); edgeGlowBottom.setAccessible(true); EdgeEffect ee = (EdgeEffect) edgeGlowTop.get(scrollView); ee.setColor(color); ee = (EdgeEffect) edgeGlowBottom.get(scrollView); ee.setColor(color); } catch (Exception ex) { ex.printStackTrace(); } } }
public static boolean onAbsorb(Object edgeEffect, int velocity) { ((EdgeEffect) edgeEffect).onAbsorb(velocity); return true; }
public static boolean onRelease(Object edgeEffect) { EdgeEffect eff = (EdgeEffect) edgeEffect; eff.onRelease(); return eff.isFinished(); }
public static boolean onPull(Object edgeEffect, float deltaDistance) { ((EdgeEffect) edgeEffect).onPull(deltaDistance); return true; }
public static void finish(Object edgeEffect) { ((EdgeEffect) edgeEffect).finish(); }
public static void setSize(Object edgeEffect, int width, int height) { ((EdgeEffect) edgeEffect).setSize(width, height); }