Android app 置灰

55 阅读1分钟
  • 设置某个Activity为灰色
public void changeViewGray(Activity activity){
    ColorMatrix matrix= new ColorMatrix();
    matrix.setSaturation(0);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(matrix));
    activity.getWindow().getDecorView().setLayerType(View.LAYER_TYPE_HARDWARE, paint);
}

  • 设置某个布局为灰色
public void setViewGray(View view) {
	Paint paint = new Paint();
	ColorMatrix cm = new ColorMatrix();
	cm.setSaturation(0);
	paint.setColorFilter(new ColorMatrixColorFilter(cm));
	view.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
}

在需要的地方调用即可