如何用不透明填充矩形

时间:2022-11-20 21:38:21

I can fill rectangle with canvas draw rect:

我可以用画布绘制矩形填充矩形:

Rect rt = new Rect(0, 0, getWidth(), getHeight());
myPaint.setColor(myColor);
myPaint.setStyle(Style.FILL);
canvas.drawRect(rt, myPaint);

But I need the method to fill rectangle with the opacity (in percent, with 0% is TRANSPARENT).
How can I do that?

但是我需要用不透明填充矩形的方法(百分比,0%是透明的)。我怎么做呢?

1 个解决方案

#1


14  

You can use the Alpha property of Paint class.

您可以使用Paint类的Alpha属性。

myPaint.setAlpha(10); will help you.

myPaint.setAlpha(10);会帮助你。

#1


14  

You can use the Alpha property of Paint class.

您可以使用Paint类的Alpha属性。

myPaint.setAlpha(10); will help you.

myPaint.setAlpha(10);会帮助你。