Issue
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?
Solution
Why is that
Usually, the background for a Button
is a ColorStateList
: specific colors are assigned to different states like "enabled" or "disabled" (possible states depend on the type of widget). If the state changes, the runtime changes the color of the background accordingly.
You provided a single color as the Button
's background, so it will be used no matter what the current state of the Button
is.
and how can I make it grey whatever happens to it?
Create a drawable resource containing a ColorStateList
(following for example this guide) and use it as the background drawable.
Answered By - Bö macht Blau
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.