Reputation: 408
I want to create a component with a color in it background , this color is variable from green to red ... well I have a courses class with limit places for example 10 places = 100%, students can join this class so for each student i need to calculate the percentage and using this percentage I change the color of the component until 100% and here the component will have Red color that's mean there is no other place
Upvotes: 0
Views: 220
Reputation: 1295
You need something like this
private int getcolorPercentage(float percent) {
return (Integer) new ArgbEvaluator().evaluate(percent, 0xff00ff00, 0xffff0000);
}
Usage
int percent = 10;
view.setBackgroundColor(getcolorPercentage((float)percent/100));
Reference:
android/animation/ArgbEvaluator
Upvotes: 1