Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button.setEnabled(false) does not make the button grey

I have a Button in my application. When I use setEnabled(false) on it, it turns grey. However if I first modify the background of the Button and then call setEnabled(false) on it, it does not turn grey (but the Button is not enabled). Why is that and how can I make it grey whatever happens to it?

like image 487
Bazouk55555 Avatar asked Apr 08 '26 03:04

Bazouk55555


1 Answers

In my opinion, the easiest solution would be to set the background of the button in your activity. Like the following:

button.setAlpha(.5f);
button.setClickable(false);

.5f alpha is equivalent to grey disable button. It's often useful if the background of your button is an image.

like image 187
Nero Avatar answered Apr 10 '26 17:04

Nero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!