How to change style of Horizontal ProgressBar in Android

Author: | Posted in Android, Code Tricks No comments

In this tutorial we will learn how to customize or change style of Horizontal Progressbar in Android.

To change style of Horizontal ProgressBar we have to set a property android:progressDrawable with custom layer-list drawable in our layout file like:

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="120dp"
android:layout_height="15dp"
android:progress="50"
android:max="100"
android:secondaryProgress="0"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/customprogressbar"
/>

 

and create progressDrawable like below in drawable folder (customprogressbar.xml)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="25dip" />
<gradient android:startColor="#C3C3C3" android:centerColor="#F8F8F8"
android:centerY="0.75" android:endColor="#ffffff" android:angle="90" />
<stroke android:width="1dp" android:color="#6B8E23" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="25dip" />
<gradient android:startColor="#9ACD32" android:endColor="#FFFF00"
android:angle="90" />
<stroke android:width="1dp" android:color="#6B8E23" />
</shape>
</clip>
</item>
</layer-list>

Now run your application and check the new style of ProgressBar, change colors value according to your requirement.

(Visited 255 times, 1 visits today)