Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill rectangle with opacity in android

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?

like image 347
ductran Avatar asked Apr 27 '12 09:04

ductran


People also ask

How do I change the opacity of a shape in Android?

In general you just have to define a slightly transparent color when creating the shape. You can achieve that by setting the colors alpha channel. #FF000000 will get you a solid black whereas #00000000 will get you a 100% transparent black (well it isn't black anymore obviously).

How do I reduce opacity on my Android?

Use imageView. setAlpha(100) .


1 Answers

You can use the Alpha property of Paint class.

myPaint.setAlpha(10); will help you.

like image 55
Mohammed Azharuddin Shaikh Avatar answered Sep 28 '22 06:09

Mohammed Azharuddin Shaikh