Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting transparency for widget background

I have a homescreen widget, with linear layout. I'm trying to set Alpha for the background during runtime using remote views, but the widget doesn't load.

I'm using this:

remoteView.setFloat(R.id.widget_background, "setAlpha", (float)0.7);

Setting background color or text color the same way, works. How can I set the background transparency using remote views?

like image 289
domen Avatar asked Mar 25 '26 10:03

domen


1 Answers

There is a simple solution using background color in hex. You have a color, for example RED - #ff0000

to set background red to your app widget, you can use:

widget.setInt(R.id.widget_list, "setBackgroundColor", Color.parseColor("#ff0000"));

for color transparency just add in front of your color how much color - transparency rapport you want, for example:

for 20% color will be #20ff0000: enter image description here

for 85% color #85ff0000 wou'll have: enter image description here

like image 90
Choletski Avatar answered Mar 28 '26 01:03

Choletski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!