I would like to know how to set the button color programatically? I have coded the following but fails:
Button11.setBackgroundColor(R.color.red);
Using setBackgroundColor() affects the style. So, declare a new style of the same properties with respect to the previous button, with a a different color.
Now, use OnClick method.
location.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
location.setBackgroundResource(R.drawable.green);
}
});
this changes the button but looks similar to changing the background.