Search code examples
androidandroid-canvasandroid-custom-view

Android Canvas Clear with transparency


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


Solution

  • Use the following.

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