I have a problem in using alpha value. I know how to set alpha value for background but I don't know how to set 20% alpha value for ImageButton.
imageButton.setAlpha(?)
Can anyone give me full details tutorial on this topic by which I can understand this topic better?
"alpha" is used to specify the opacity for an image. set alpha using XML attribute: android:alpha="0.5" Note: takes float value from 0 (transparent) to 1 (fully visible)
Here is a simple function to change the opacity of a view in android. Opacity is called alpha in android. so setAlpha(int) will do the job. ImageView img = (ImageView)findViewById(R.
Save the XML file in your project res/drawable/ folder and then reference it as a drawable for the source of your ImageButton (in the android:src attribute). Android will automatically change the image based on the state of the button and the corresponding images defined in the XML.
You don't need a tutorial for this, just read the javadoc of the method, which says:
setAlpha() - Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.
20% transparent then would mean a value of 0.2.
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