How to change the color of overscroll edge and overscroll glow

前端 未结 4 1642
小鲜肉
小鲜肉 2020-12-14 14:55

How to Change color of over-scroll edge and over-scroll glow or how to change the white color (default color) of android release 5.0 lollipop?

4条回答
  •  一个人的身影
    2020-12-14 15:19

    In pre-lollipop the glow effect is actually a Drawable embedded in the OS's resources, you can apply a ColorFilter on that:

    public static void changeOverScrollGlowColor(Resources res, int colorID ) {
        try {
            final int glowDrawableId = res.getIdentifier("overscroll_glow", "drawable", "android");
            final Drawable overscrollGlow = res.getDrawable(glowDrawableId);
            overscrollGlow.setColorFilter(res.getColor(colorID), android.graphics.PorterDuff.Mode.SRC_ATOP);
    
            final int edgeDrawableId = res.getIdentifier("overscroll_edge", "drawable", "android");
            final Drawable overscrollEdge = res.getDrawable(edgeDrawableId);
            overscrollEdge.setColorFilter(res.getColor(colorID), android.graphics.PorterDuff.Mode.SRC_ATOP);
        } catch (Exception ignored) {
        }
    }
    

    Calling it once in onCreate is enough.

    changeOverScrollGlowColor(getResources(), R.color.colorPrimary);
    

提交回复
热议问题