Android实现APP黑白化
使用硬件加速的方法来达到黑白化效果。
先上效果图吧
黑白化之前:
黑白化之后:
实现代码:
Paint mPaint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
mPaint.setColorFilter(new ColorMatrixColorFilter(cm));
getWindow().getDecorView().setLayerType(View.LAYER_TYPE_HARDWARE, mPaint);
把上面的方法放到BaseActivity的onCreate方法就可以了。
主要是调用API : view.setLayerType(layerType, null);
注意:上面的方法不能使状态栏黑白化。
参考文章:https://blog.csdn.net/Q___0/article/details/105438954