Reputation: 11
I have to set the background color during run time, i am using "setBackgroundColor(R.color.focusColor)" . but its nots working.
Upvotes: 1
Views: 7279
Reputation: 5
its simplest way ((Button)findViewById(R.id.yourButtonResId)).setBackground(#ffffff);
Upvotes: 0
Reputation: 5140
You can use button.setBackgroundColor(Color.BLUE);
BLUE can be replaced by the color you want if its available!
Upvotes: 0
Reputation: 17850
You can use the PorterDuff.Mode
enum with its properties.
((Button)findViewById(R.id.yourButtonResId)).getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
Here's the result containing an unchanged default Pass button and a Submit button on which I applied the line above:
More details on this matter here.
Upvotes: 2
Reputation: 1729
To Google travelers, if this is a Drawable update (e.g. you are going to update your button that already have a drawable, such as button.getBackground.doStuff()
) you need to use Button.invalidateSelf().
Upvotes: 0
Reputation: 6686
May be this question can help you a bit.
In a nutshell you have to use this.getResources().getColor(R.color.orange)
in argument.
**EDIT: ** Pasted a wrong code. Edited
Try this.
Upvotes: 0
Reputation: 1765
use setBackgroundColor(Color.color)" or setBackgroundColor("#000000");
Upvotes: 3