是否可以在 Drawable
中“反转”颜色?你有什么负面的,你知道吗?
我知道可以将 Drawable
更改为黑白,但是反转颜色呢?
最佳答案
经过一番研究,我发现解决方案比我想象的要简单得多。
这里是:
/**
* Color matrix that flips the components (<code>-1.0f * c + 255 = 255 - c</code>)
* and keeps the alpha intact.
*/
private static final float[] NEGATIVE = {
-1.0f, 0, 0, 0, 255, // red
0, -1.0f, 0, 0, 255, // green
0, 0, -1.0f, 0, 255, // blue
0, 0, 0, 1.0f, 0 // alpha
};
drawable.setColorFilter(new ColorMatrixColorFilter(NEGATIVE));
关于android - 反转drawable的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17841787/