0

I have LinearLayout containing some views. Is it possible to do so that everything inside LinearLayout are drawn in grayscale color mode?

Egis
  • 5,081
  • 5
  • 39
  • 61
  • 1
    Set the layout as disabled? –  May 16 '16 at 13:40
  • do you mean to something like this: http://stackoverflow.com/questions/7068873/how-can-i-disable-all-views-inside-the-layout ? – AsfK May 16 '16 at 13:43

1 Answers1

0

you need to extends LinearLayout and override dispatchDraw method.

then create a Bitmap with the size of LinearLayout and a canvas. and call super.dispatchDraw with new canvas as parameter. after that you draw the bitmap on the original Canvas with a paint setting a ColorFilter.

here's the example:

private Bitmap mBitmap;
private Canvas mCanvas;
private Paint mPaint;

public {Constructor}{
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);

    ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
    mPaint.setColorFilter(colorFilter);
}

@Override
public void onSizeChanged(int w, int h, in oldw, int oldh){
    mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    mCanvas = new Camvas(mBitmap);
}

@Override
public void dispatchDraw(Canvas canvas){
    super.dispatchDraw(mCanvas);

    canvas.drawBitmap(mBitmap, 0, 0, mPaint);
}
7heaven
  • 797
  • 7
  • 16