Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set drawable opacity

How can i set the opacity of a Drawable object?

like image 629
james Avatar asked Oct 18 '10 15:10

james


People also ask

How do you change opacity in XML?

For a fully opaque option i.e. 100% opacity, you do not need to use #FFC0C0C0 or #100C0C0C0(Note: this would show nothing). Just leave it as #C0C0C0 instead. The alpha channel A is a hex value, just like the RGB channels. #50C0C0C0 will give an opacity of about 30%, not 50%.

How do you change opacity on Android?

setAlpha(51); Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.

What is setColorFilter?

setColorFilter(ColorFilter colorFilter) Specify an optional color filter for the drawable.


1 Answers

You can use Drawable's setAlpha() method. It takes an int from 0 to 255, 0 being fully transparent, and 255 being fully opaque.

See the developer reference here.

like image 60
Kevin Coppock Avatar answered Sep 27 '22 22:09

Kevin Coppock