这是我用于setColorFilter、ColorMatrix 和ColorMatrixColorFilter的实验:
drawable.setColorFilter(item.getColorMatrix());
或:
drawable.setColorFilter(new ColorMatrixColorFilter(getColorMatrix5()));//custom 5
//custom 5
private ColorMatrix getColorMatrix5()
{
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);//make it greyscale
ColorMatrix blueMatrix = new ColorMatrix(new float[] {
0, 0, 0, 0, 0, // red
0, 0, 0, 0, 0, // green
1, 1, 1, 1, 1, // blue
1, 1, 1, 1, 1 // alpha
});
// Convert, then scale and clamp
colorMatrix.postConcat(blueMatrix);
return colorMatrix;
}//getColorMatrix5
参见PorterDuff , PorterDuff.Mode
, PorterDuffXfermode
, ColorFilter
, ColorMatrix , ColorMatrixColorFilter , PorterDuffColorFilter , Canvas
, Color
。