so i have a Layer-List with an Item with a shape and a solid color. Now i want to change this color inside my code.
I know this question is a few months old but I was able to get a level-list working with a progress bar. The trick is to assign your levels values between 0 and 10,000 In my particular example I had 3 levels (red/yellow/green) used to represent battery life.
Here is how I did it:
res/drawable/progress_horizontal_yellow.xml
-
-
-
res/drawable/progress_horizontal_red.xml
-
-
-
res/drawable/progress_horizontal_green.xml
-
-
-
res/drawable/battery_charge_fill.xml
Then in the layout file my progress bar declaration was like this:
Then in java:
//progress is between 0 and 100 so set level of drawable to progress * 100
Drawable batteryProgressD = batteryProgressBar.getProgressDrawable();
batteryProgressD.setLevel(progress*100);
batteryProgressBar.setProgress(progress);