Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 629
Alon Levanon Avatar asked Feb 18 '14 19:02

Alon Levanon


People also ask

How do you make a button background transparent?

CSS Code: In this section, we will design the button using CSS property. We will use the background-color: transparent; property to set the button with transparent look. Complete Code: In this section, we will combine the above two sections to create a transparent background button.

How do you change opacity on Android?

setAlpha(51); Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.

Which attribute is used to change the background color of button in Android?

If you want just to change the color, use the app:backgroundTint attribute.

How do you set up Alpha?

To get α subtract your confidence level from 1. For example, if you want to be 95 percent confident that your analysis is correct, the alpha level would be 1 – . 95 = 5 percent, assuming you had a one tailed test. For two-tailed tests, divide the alpha level by 2.


2 Answers

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.

like image 89
Triode Avatar answered Sep 19 '22 08:09

Triode


Try this:

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

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

like image 40
notdrone Avatar answered Sep 21 '22 08:09

notdrone