I have a custom progress drawable for my horizontal progress bar
Below is progress bar:
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:progress="20"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Below is progress bar drawable:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<stroke
android:width="3px"
android:color="#648A5E" />
<corners android:radius="5dp"
android:color="#d6f0d6"/>
<gradient
android:angle="270"
android:centerColor="#d6f0d6"
android:centerY="0.5"
android:endColor="#d6f0d6"
android:startColor="#d6f0d6" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<stroke
android:width="3px"
android:color="#648A5E" />
<corners android:radius="5dp"
android:color="#d6f0d6"/>
<gradient
android:angle="270"
android:centerColor="#d6f0d6"
android:centerY="0.5"
android:endColor="#d6f0d6"
android:startColor="#d6f0d6" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<scale android:scaleWidth="100%">
<shape>
<stroke
android:width="3px"
android:color="#B1707C" />
<corners android:radius="5dp"
android:color="#fce0e6"/>
<gradient
android:angle="0"
android:endColor="#fce0e6"
android:startColor="#fce0e6" />
</shape>
</scale>
</item>
</layer-list>
Below is the code i attempt for programmatically creation of custom progress drawable
Drawable bckgrndDr = new ColorDrawable(Color.parseColor("#e1203e"));
Drawable secProgressDr = new ColorDrawable(Color.parseColor("#eeeeee"));
Drawable progressDr = new ScaleDrawable(new ColorDrawable(Color.BLUE), Gravity.LEFT, 1, -1);
LayerDrawable resultDr = new LayerDrawable(new Drawable[] { bckgrndDr, secProgressDr, progressDr });
resultDr.setId(0, android.R.id.background);
resultDr.setId(1, android.R.id.secondaryProgress);
resultDr.setId(2, android.R.id.progress);
progressBar.setProgressDrawable(resultDr);
progressBar.setProgress(40);
I am unable to set the stroke,corners and gradient for id background ,secondaryProgress and progress. Please suggest what should i do to programtically create and change the color for entire custom progress drawable.