由于listview等可以overscroll的view的边界颜色不同一,3.0以前是屎黄色,3.0以后是holo blue,该颜色是使用系统的drawable资源实现的,该颜色有2部分组成,一个是edge边缘色,一个是glow长渐变色
通过更改系统的drawable资源,来实现自定义颜色的目的:
void customEdgeEffect(Context context, int brandColor) {
//glow
int glowDrawableId = context.getResources().getIdentifier("overscroll_glow", "drawable", "android");
Drawable androidGlow = context.getResources().getDrawable(glowDrawableId);
androidGlow.setColorFilter(brandColor, PorterDuff.Mode.MULTIPLY);
//edge
int edgeDrawableId = context.getResources().getIdentifier("overscroll_edge", "drawable", "android");
Drawable androidEdge = context.getResources().getDrawable(edgeDrawableId);
androidEdge.setColorFilter(brandColor, PorterDuff.Mode.MULTIPLY);
}
注:该方法并不是完全有效,设置完自定义颜色后还会有暗灰色,暂时无法去掉,