How to fill rectangle with opacity in android

R4j picture R4j · Apr 27, 2012 · Viewed 21.7k times · Source

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?

Answer

Mohammed Azharuddin Shaikh picture Mohammed Azharuddin Shaikh · Apr 27, 2012

You can use the Alpha property of Paint class.

myPaint.setAlpha(10); will help you.