颜色相关代码

颜色渐变

/** fraction : 分量 
private int evaluate(float fraction, int startValue, int endValue) {
        int startInt = startValue;
        int startA = (startInt >> 24);
        int startR = (startInt >> 16) & 0xff;
        int startG = (startInt >> 8) & 0xff;
        int startB = startInt & 0xff;

        int endInt = endValue;
        int endA = (endInt >> 24);
        int endR = (endInt >> 16) & 0xff;
        int endG = (endInt >> 8) & 0xff;
        int endB = endInt & 0xff;

        return ((startA + (int) (fraction * (endA - startA))) << 24) | ((startR + (int) (fraction * (endR - startR))) << 16) | ((startG + (int) (fraction * (endG - startG))) << 8)
                | ((startB + (int) (fraction * (endB - startB))));
    }

获取深色与暗色

 private int getDarkColor(int color) {
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        return 0XFF000000 | getOffsetIntValue(red,-20) << 16 | getOffsetIntValue(green,-20) << 8 | getOffsetIntValue(blue,-20);
    }

    private int getDeepColor(int color) {
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        return 0XFF000000 | getOffsetIntValue(red,20) << 16 | getOffsetIntValue(green,20) << 8 | getOffsetIntValue(blue,20);
    }

动态改变 Progress 的颜色

 if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP){
            progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
        }

你可能感兴趣的:(颜色相关代码)