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.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<clip>
<shape android:id="@+id/seekbar_shape_color">
<solid android:color="#FFD00000" />
</shape>
</clip>
</item>
</layer-list>
i tryed getting the LayerDrawable and requesting the first item, now iam stuck getting the clipDrawable and finally get the ShapeDrawable
LayerDrawable sd = (LayerDrawable) v.getResources().getDrawable(R.drawable.seekbar_progress_bg);
((ClipDrawable) sd.getDrawable(0)).get..();
my other approach was to get the ShapeDrawable and setting the color with colorFilter but that doesnt work either.
ShapeDrawable sd = (ShapeDrawable) v.getResources().getDrawable(R.id.seekbar_shape_color);
sd.setColorFilter(R.color.cold_color,PorterDuff.Mode.MULTIPLY);
edit: ok so i developed a new plan
i tryed to use a LevelList like
<level-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0" android:drawable="@color/hot_color">
</item>
<item android:maxLevel="1" android:drawable="@color/cold_color">
</item>
</level-list>
i think the default value for Level is 0 but i dont get the progressbar displayed with the LevelList.
Also i dont know on which element i have to set the setLevel()
holder.progressbar.getBackground().setLevel(0);
holder.progressbar.getIndeterminateDrawable().setLevel(0);
holder.progressbar.getProgressDrawable().setLevel(0);
this calls give me strange results like only fresh progressbar items getting 100% progress coloration, smells like caching problem.
hope somebody can enlighten me how to use the LevelList properly on an LayerList for a Progressbar
thanks
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: