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 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

Leave a Reply

Your email address will not be published. Required fields are marked *