如何改变图像按钮透明度编程



如何在android中编程设置图像按钮的透明度?我正在动态创建图像按钮。

您应该能够使用以下命令更改按钮:

btnMybutton.getBackground().setAlpha(45);

ImageButton.setBackgroundColor(Color.TRANSPARENT)应该可以解决这个问题。

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

将背景设置为给定的Drawable,或者删除背景。如果背景有填充,这个视图的填充被设置为背景填充。然而,当背景被移除时,这视图的填充没有被触碰。如果需要设置填充,请使用setPadding(int, int, int, int)

我喜欢这样:

imageButton.setImageAlpha(alpha_value); //alpha_value between 0...255

最新更新