我有以下代码来激活/停用橡皮擦:
public PorterDuffXfermode clear = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
eraseB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!eraser) {
eraser = true;
eraseB.setImageResource(R.drawable.erase_on);
paint = new Paint(Paint.DITHER_FLAG);
paint.setColor(0x00000000);
paint.setAlpha(0x00);
paint.setXfermode(clear);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(stroke);
paintv.setPaint(paint);
} else {
eraser = false;
eraseB.setImageResource(R.drawable.erase);
paint = new Paint(Paint.DITHER_FLAG);
paint.setDither(true);
paint.setXfermode(null);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(stroke);
paintv.setPaint(paint);
}
}
});
setPaint 来自我的 customView:
public void setPaint(Paint paint) {
this.paint = paint;
LogService.log("in setPaint", "paint = " + paint);
}
和 onDraw 我使用:
canvas.drawPath(mPath, paint);
如果我停用橡皮擦,它会画一条红线,但是,如果我激活橡皮擦,它不会擦除,而是画一条黑线。我怎样才能解决这个问题