如何改变卷帘边缘的颜色和卷帘的光晕

如何更改过度滚动的边缘和过度滚动发光的颜色或如何更改android发行版5.0棒棒糖的白色(默认颜色)?

Solutions Collecting From Web of "如何改变卷帘边缘的颜色和卷帘的光晕"

overscroll发光颜色inheritance了android:colorPrimary在您的整个应用程序中设置的主要颜色值。 但是,如果你需要指定不同的值,只需使用android:colorEdgeEffect

 <style name="MyAppTheme" parent="***"> <item name="android:colorEdgeEffect">@color/my_color</item> </style> 

LOLLIPOP ,边缘辉光从colorPrimaryinheritance。 在创build视图之后,边缘发光颜色只能通过reflection来改变。 当使用Palettedynamic加载颜色时,这会很有用。

编辑:TL; DR:从这里下载整个类: https : //github.com/consp1racy/android-commons/blob/master/commons/src/main/java/net/xpece/android/widget/XpEdgeEffect.java

程序设置:如果你打算在支持库的小部件上使用这个,你需要保留字段名称。 最快的方法是(尽pipe仍然是浪费):

 -keepclassmembers class * extends android.view.View { <fields>; } -keepclassmembers class android.support.v4.widget.EdgeEffectCompat { <fields>; } 

用下面的代码创build一个实用程序类:

 private static final Class<?> CLASS_SCROLL_VIEW = ScrollView.class; private static final Field SCROLL_VIEW_FIELD_EDGE_GLOW_TOP; private static final Field SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM; private static final Class<?> CLASS_LIST_VIEW = AbsListView.class; private static final Field LIST_VIEW_FIELD_EDGE_GLOW_TOP; private static final Field LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM; static { Field edgeGlowTop = null, edgeGlowBottom = null; for (Field f : CLASS_SCROLL_VIEW.getDeclaredFields()) { switch (f.getName()) { case "mEdgeGlowTop": f.setAccessible(true); edgeGlowTop = f; break; case "mEdgeGlowBottom": f.setAccessible(true); edgeGlowBottom = f; break; } } SCROLL_VIEW_FIELD_EDGE_GLOW_TOP = edgeGlowTop; SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM = edgeGlowBottom; for (Field f : CLASS_LIST_VIEW.getDeclaredFields()) { switch (f.getName()) { case "mEdgeGlowTop": f.setAccessible(true); edgeGlowTop = f; break; case "mEdgeGlowBottom": f.setAccessible(true); edgeGlowBottom = f; break; } } LIST_VIEW_FIELD_EDGE_GLOW_TOP = edgeGlowTop; LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM = edgeGlowBottom; } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static void setEdgeGlowColor(AbsListView listView, int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { EdgeEffect ee; ee = (EdgeEffect) LIST_VIEW_FIELD_EDGE_GLOW_TOP.get(listView); ee.setColor(color); ee = (EdgeEffect) LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM.get(listView); ee.setColor(color); } catch (Exception ex) { ex.printStackTrace(); } } } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static void setEdgeGlowColor(ScrollView scrollView, int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { EdgeEffect ee; ee = (EdgeEffect) SCROLL_VIEW_FIELD_EDGE_GLOW_TOP.get(scrollView); ee.setColor(color); ee = (EdgeEffect) SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM.get(scrollView); ee.setColor(color); } catch (Exception ex) { ex.printStackTrace(); } } }