//蒙版色值
private int color = Color.parseColor(“#81FFFFFF”);
//是否显示蒙版
private boolean isShowMask = false;
public MaskImageView(Context context) {
super(context);
this.context = context;
}
public MaskImageView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
public MaskImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
}
@SuppressLint(“DrawAllocation”)
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isShowMask) {
canvas.drawColor(color);
}
}
/**
- 设置蒙版颜色,可以通过类似于(#81FFFFFF)来控制透明度
*/
public MaskImageView setMaskColor(int color) {
this.color = color;
return this;
}
/**
- 显示蒙版
*/
public void showMask() {
isShowMask = true;
invalidate();
}
/**
- 关闭蒙版
*/
public void dismissMask() {
isShowMask = false;
invalidate();
}
/**</