How can i set the opacity of a Drawable
object?
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%.
setAlpha(51); Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.
setColorFilter(ColorFilter colorFilter) Specify an optional color filter for the drawable.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With