Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change image button transparency programmatically?

How to set the transparency of the image button programmatically in android? I am creating dynamic image buttons on the fly.

like image 317
ssk Avatar asked Dec 05 '22 19:12

ssk


2 Answers

You should be able to change a button with the following:

btnMybutton.getBackground().setAlpha(45);
like image 167
Scott Tomaszewski Avatar answered Dec 07 '22 07:12

Scott Tomaszewski


ImageButton.setBackgroundColor(Color.TRANSPARENT) Should solve the problem.

From http://developer.android.com/reference/android/view/View.html#setBackgroundColor%28int%29

Set the background to a given Drawable, or remove the background. If the background has padding, this View's padding is set to the background's padding. However, when a background is removed, this View's padding isn't touched. If setting the padding is desired, please use setPadding(int, int, int, int).

like image 31
iraSenthil Avatar answered Dec 07 '22 08:12

iraSenthil