6

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?

Alon Levanon
  • 691
  • 5
  • 18

2 Answers2

7
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.

Triode
  • 11,309
  • 2
  • 38
  • 48
2

Try this:

<Button
    android:background="#3000"
    android:text="Button"
    />

here #3000 => #argb where 'a' sets the alpha component.

notdrone
  • 1,793
  • 15
  • 12