一、黑白模式

/**
     * 设置灰白色
     *
     * @param window
     */
    protected void setGrayScreen() {
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        getWindow().getDecorView().setLayerType(View.LAYER_TYPE_HARDWARE, paint);
    }


    /**
     * 设置原色
     *
     * @param window
     */
    protected void setOriginalScreen() {
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(1);
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        getWindow().getDecorView().setLayerType(View.LAYER_TYPE_HARDWARE, paint);
    }

二、黑夜模式

/**
     * @param isNightMode 控制是白天还是夜晚
     */
    protected void setNightOrLightMode(boolean isNightMode) {
        if (isNightMode) {
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION,
                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            if (myView == null) {
                myView = new View(this);
                myView.setBackgroundColor(0x70000000);
            }
            mWindowManager.addView(myView, params);
        } else {
            if (myView != null) {
                mWindowManager.removeView(myView);
            }
        }
    }

使用:在基类BaseActivity中实现置灰方法,其他Activity继承基类。