Android APP interface black and white processing

Android page grayed out

Solution 1. The Android page drawing process is generally divided into measure, layout, and draw, and the page graying drawis implemented in the method. drawThe method parameters include canvas, paint, canvaswhich is the canvas of the interface, paintand the brush for drawing the interface. You can change the interface background color by changing paintthe properties, and change the hue, saturation and brightness of the brush by setting the color filter. Set the saturation of the gray effect to 0, and the setting code of the brush:

Paint  paint = new  Paint();
ColorMatrix cm = new  ColorMatrix();
cm.setStaturation(0);
paint.setColorFilter(new ColorMatrixColorFilter(cm));

Solution 2. Considering performance Use HardwareLayer (the Buffer inside the GPU) to cache the drawn graphics. The setter method setLayerType()forces Viewthe creation of its own corresponding layer, and draws itself onto the layer.

Solution 3. Set graying on the Activitytop layer to achieve the global graying effect. ViewGet the root of the interface View:

//java
View view  = activity. getWindow(). getDecorView();
 Paint paint = new  Paint();
ColorMatrix cm = new  ColorMatrix();
cm.setStaturation(0);
paint.setColorFilter(new ColorMatrixColorFilter(cm));
view. setLayerType(View.LAYER_TYPE_HARDWARE, paint);
//kotlin
val view: View = window.decorView
val paint = Paint()
val cm = ColorMatrix()
cm.setSaturation(0f)
paint.colorFilter = ColorMatrixColorFilter(cm)
view.setLayerType(View.LAYER_TYPE_HARDWARE, paint)

Guess you like

Origin blog.csdn.net/chennai1101/article/details/130710148