I have this code
pb = (ProgressBar) findViewById(R.id.progressBar1);
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
ShapeDr
Specify a progressDrawable
like in the example below:
This goes to a layout:
<ProgressBar
android:id="@+id/gauge"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="4dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/section"
android:progress="50"
android:progressDrawable="@drawable/progressbar"/>
This goes to drawable/progressbar.xml
, and here you can specify background and colors for both progress bars.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<gradient
android:startColor="@color/basecolor"
android:endColor="@color/basecolor"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="#808080"
android:endColor="#808080"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#ffcc33"
android:endColor="#ffcc33"
android:angle="270" />
</shape>
</clip>
</item>
I have also faced the same issue. I add some extra points to the above answer. The seekbar or progressbar is drawn in three layers. First layer is background layer, above that secondary progress layer, above that primary progress.
you can set your custom color to progressbar like this
<item android:id="@android:id/background"
android:drawable="@drawable/progress_bar_nor">
</item>
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/progress_bar_nor">
</item>
<item
android:id="@android:id/progress"
android:drawable="@drawable/progress_bar_sel"/>
or like Ridcully said in above answer
It happens that some android os versions do not use the background color of secondary progress. I have checked on android 4.1.2 samsung 8 inch tablet. It doesnot work. In that scenario use background to set your custom color for the secondary progress by setting background, secondary progress color