Custom Progress bar- with multiple colors

 

reference link

https://android-dev-examples.blogspot.in/2014/09/android-custom-horizontal-progressbar.html

progrossactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:padding="20dp">
 <ProgressBar
  style="@android:style/Widget.ProgressBar.Horizontal"
  android:layout_centerInParent="true"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:max="100"
  android:progress="50"
  android:progressDrawable="@drawable/progress_drawable" />
</RelativeLayout>

Progress_drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:id="@android:id/background">
  <shape>
   <solid android:color="#777" />
   <size
    android:width="15dp"
    android:height="15dp" />
   <corners android:radius="10dp" />
  </shape>
 </item>
 <item android:id="@android:id/progress">
  <clip>
   <layer-list>
    <item>
     <color android:color="#00000000" />
    </item>
    <item
     android:left="2dp"
     android:top="2dp"
     android:right="2dp"
     android:bottom="2dp">
     <shape>
      <gradient
       android:startColor="#00FF00"
       android:centerColor="#FFFF00"
       android:endColor="#FF0000" />
      <size
       android:width="15dp"
       android:height="15dp" />
      <corners android:radius="10dp" />
     </shape>
    </item>
   </layer-list>
  </clip>
 </item>
</layer-list>

 

Leave a comment