Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set 20% alpha value for Android Imagebutton?

Tags:

android

view

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?

like image 525
androidcodehunter Avatar asked Aug 23 '13 08:08

androidcodehunter


People also ask

What is alpha value in android?

"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)

How do I change opacity of an image in android?

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.

How to use ImageButton in android studio?

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.


1 Answers

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.

like image 169
Andy Res Avatar answered Oct 16 '22 10:10

Andy Res