I have an drawing app for Android and I am currently trying to add a real eraser to it. Before, I had just used white paint for an eraser, but that won\'t do anymore since n
I could suggest you to read the official sample of FingerPaint.java
It exactly matches what you are trying to achieve here.
To not show the trail when you erase content, take a look at the onDraw() method and the eraserMode variable:
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
if (!eraserMode) {
canvas.drawPath(mPath, mPaint);
}
}
boolean eraserMode = false;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
eraserMode = false;
mPaint.setXfermode(null);
mPaint.setAlpha(0xFF);
switch (item.getItemId()) {
/*...*/
case ERASE_MENU_ID:
// Add this line
eraserMode = true;
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
return true;
/*...*/
}
return super.onOptionsItemSelected(item);
}