How to fill rectangle with opacity in android

喜夏-厌秋 提交于 2019-12-21 08:00:17

问题


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?


回答1:


You can use the Alpha property of Paint class.

myPaint.setAlpha(10); will help you.



来源:https://stackoverflow.com/questions/10348084/how-to-fill-rectangle-with-opacity-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!