Android Canvas Clear with transparency
The solution was to create a secondary canvas and bitmap to draw on. My Custom View's onSizeChanged() method looked like
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
bitmap.eraseColor(Color.TRANSPARENT);
temp = new Canvas(bitmap);
}
and the onDrawMethod looks like
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
temp.drawColor(Color.argb(80, 0, 0, 0));
temp.drawCircle(centerPosX, centerPosY, 200, transparentPaint);
canvas.drawBitmap(bitmap, 0, 0, null);
}
where transparentPaint is declared in the onstructor as
transparentPaint = new Paint();
transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
transparentPaint.setAntiAlias(true);
Use the following.
canvas.drawColor(Color.TRANSPARENT,Mode.CLEAR);