Android_黑白主题工具类

/**
 * 页面置灰
 */
public class SaturationView {
    private final Paint paint = new Paint();
    private final ColorMatrix cm = new ColorMatrix();

    private SaturationView() {
    }

    private static SaturationView instance;

    /**
     * get instance
     *
     * @return
     */
    public static SaturationView getInstance() {
        synchronized (SaturationView.class) {
            if (instance == null) {
                instance = new SaturationView();
            }
        }
        return instance;
    }

    /**
     * saturation view
     *
     * @param view
     * @param saturation 【0f:灰色 ---- 1f:正常色】
     */
    public void saturationView(View view, float saturation) {
        cm.setSaturation(saturation);
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        view.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
    }

}

在相应的Activity中进行使用

  SaturationView.getInstance().saturationView((context as Activity?)!!.window.decorView, 0f)

你可能感兴趣的:(Android_黑白主题工具类)