Change background alpha code of button without changing alpha text value in Android?

I have a button with an image background and text. Background alpha should be 0.7 and alpha text should be 1.0.

<Button
android:background="@drawable/button"
android:alpha="0.7"
android:text="Button"
/>

For this code, I get 0.7 alpha for the whole button. Is there a way to change only scalable alpha?

+4
source share
2 answers
myButton.getBackground().setAlpha(200); 

can try this in your code.

public abstract void setAlpha (int alpha)

Added to API Level 1

Specify the alpha value for the selection. 0 means completely transparent, and 255 means completely opaque.

+2
source

Try the following:

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

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

+2
source

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


All Articles