@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(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();
      }
    }
  }
Ejemplo n.º 3
0
 @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
   }
 }