Change button's background alpha without changing the text alpha value in Android?

android, graphics, xml

Solution

myButton.getBackground().setAlpha(200); 

can try this in your code.

public abstract void setAlpha (int alpha)

Added in API level 1

Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.

Problem

I have a button with an image background and text. The background alpha should be 0.7 and the text alpha should be 1.0. ``` <Button android:background="@drawable/button" android:alpha="0.7" android:text="Button" /> ``` By this code I get 0.7 alpha for the whole button. Is there a way to change only the drawable alpha?

Original source