Scrollview & RecycleView & ListView & Viewpager Top/Bottom Shadow Color Change
0 Using Theme Settings
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorEdgeEffect">@color/colorAccent</item>
</style>
Note, however, that you can only set it above api21
The following methods are reflection settings
1 Scrollview
The two attributes involved, mEdgeGlowTop and mEdgeGlowBottom, are of EdgeEffect type
Direct de-reflection to change color
Take mEdgeGlowTop as an example
Field topMethod = ScrollView.class.getDeclaredField("mEdgeGlowTop");
topMethod.setAccessible(true);
EdgeEffect top = (EdgeEffect) topMethod.get(scrollView);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
top.setColor(Color.RED);
}
2 RecycleView
RecycleView has four attributes, mLeftGlow, mTopGlow, mRightGlow, mBottomGlow
It can be done in the same way as Scrollview
3 ListView
listview has a public method
/**
* Sets the drawable that will be drawn above all other list content.
* This area can become visible when the user overscrolls the list.
*
* @param header The drawable to use
*/
public void setOverscrollHeader(Drawable header) {
mOverScrollHeader = header;
if (mScrollY < 0) {
invalidate();
}
}
/**
* Sets the drawable that will be drawn below all other list content.
* This area can become visible when the user overscrolls the list,
* or when the list's content does not fully fill the container area.
*
* @param footer The drawable to use
*/
public void setOverscrollFooter(Drawable footer) {
mOverScrollFooter = footer;
invalidate();
}
4 viewpager
Viewpager also has two attributes, right and left. The reflection mode is also applicable to Scrollview. The attributes are mLeftEdge and mRightEdge.