private void init() {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(strokeColor);
mPaint.setStrokeWidth(strokeWidth);
mPaintLabel = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaintLabel.setStyle(Paint.Style.STROKE);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_support_select);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();
//http://blog.csdn.net/kuaiguixs/article/details/78753149
float offset = strokeWidth / 2;
canvas.drawColor(solidColor);
RectF rec = new RectF(offset, offset, width - offset, height - offset);
if (isSelect) {
canvas.drawRoundRect(rec, cornersRadius, cornersRadius, mPaint);
canvas.drawBitmap(bitmap, getWidth() - labelWidth, getHeight() - labelHeight, mPaintLabel);
} else {
canvas.drawRoundRect(rec, cornersRadius, cornersRadius, mPaint);
}
}
换个图吧 clippath能做到但是有点麻烦