Android Canvas Clear with transparency

rperryng picture rperryng · Feb 18, 2014 · Viewed 18.9k times · Source

I am trying to "erase" from a canvas. Just as a VERY simple test of clearing a canvas, I have implemented the following:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.argb(140, 0, 0, 0));
    canvas.drawColor(0, Mode.CLEAR);
}

Color.argb(140, 0, 0, 0) sets the view this view is drawn over to be dimmed. drawColor(0, Mode.CLEAR) makes the screen completely black, rather than removing the dimming applied earlier. The idea was taken from here

Answer

Y0Gi picture Y0Gi · May 14, 2015

Use the following.

 canvas.drawColor(Color.TRANSPARENT,Mode.CLEAR);