How to programmatically change the transparency of an image button?

How to adjust image button transparency programmatically in android? I create dynamic image buttons on the fly.

+4
source share
3 answers

You can change the button with the following:

btnMybutton.getBackground().setAlpha(45); 
+11
source

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

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

Set the background for this Drawable or remove the background. If the background has padding, this view add-on is set to the background add-on. However, when the background is removed, this Layout View is not affected. If padding is required, use setPadding (int, int, int, int).

+3
source

I like it:

 imageButton.setImageAlpha(alpha_value); //alpha_value between 0...255 
+2
source

Source: https://habr.com/ru/post/1379381/


All Articles