Android Question How can I change the background color of a button

MaFu

Well-Known Member
Licensed User
Longtime User
For general change:
button.Color = Colors.Blue
But in this case the button is blue in all states.
To use different colors for the button states (disabled, pressed, normal, ...) you must use StateListDrawable and ColorDrawables.
See example here: link
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
For general change:
button.Color = Colors.Blue
But in this case the button is blue in all states.
To use different colors for the button states (disabled, pressed, normal, ...) you must use StateListDrawable and ColorDrawables.
See example here: link
Thanks a lot, I was looking for a property in the designer. I'm assigning an RGB value like this

cmdLogin.Color = Colors.RGB(154,217,234)

but this seems to take away the corner radius/rounded corners, do you have any idea to fix that.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
To make your sub more reusable it would be better to pass the required color as a parameter. But if always wanting the same colour then of course you can stick with what you have already. ;)
 
Upvote 0
Top