Android实现APP黑白化

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

猜你喜欢

转载自blog.csdn.net/weixin_42574892/article/details/106146965