pearmak pearmak - 1 year ago 167
Android Question

android set button background programmatically

I would like to know how to set the button color programatically?
I have coded the following but fails:



Answer Source is an ID (which is also an int), but is not a color.

Use one of the following instead:

// If you're in an activity:
// OR, if you're not: 

Or, alternatively:

Button11.setBackgroundColor(Color.RED); // From

Or, for more pro skills:

Button11.setBackgroundColor(0xFFFF0000); // 0xAARRGGBB
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download