This is the most simplified version of my view.
public class MyView extends View {
private int mBackgroundColor = android.R.color.white;
@Override
public void setBackgroundColor(int color) {
super.setBackgroundColor(color);
mBackgroundColor = color;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(mBackgroundColor);]
//canvas.drawColor(mBackgroundColor, Mode.CLEAR);
//canvas.drawBitmap(mBitmap, mRectSrc, mRectDst, mPaint);
}
}
the problem is the background color does not change when the setBackgroundColor is called from the activity. i guess i’am not seeing the obvious.
SOLVED:
took hint from nmJohn about clipRect
//Clear the screen
canvas.clipRect(0, 0, viewWidth, viewHeight, Region.Op.REPLACE);
mPaint.setColor(mBackgroundColor);
canvas.drawRect(0, 0, viewWidth, viewHeight, mPaint);
//Draw the image
canvas.clipRect(mRectDst.left, mRectDst.top, mRectDst.right, mRectDst.bottom, Region.Op.REPLACE);
canvas.drawBitmap(mBitmap, mRectSrc, mRectDst, mPaint);
one more hint for the future seekers
please make sure that android.graphics.Color i.e hex format is supplied rather that android.R.color.[White/Black/..] took be unaware for a while.
drawColor just sets the background color of the current clip. Try setting clipRect to the area of the canvas.
Also, make sure your view is actually getting invalidated, otherwise onDraw will not get called.