Changing progress bar color using XML in Android app

后端 未结 2 2012
孤独总比滥情好
孤独总比滥情好 2021-01-23 16:24

I\'m trying to change the color of a horizontal progress bar (foreground). I came across this example and am trying to model my XML file off it. However, I get a compiler erro

相关标签:
2条回答
  • 2021-01-23 16:32

    Call this on your progress bar xml element

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:id="@android:id/background">  //---this is progress background
       <shape>
         <corners android:radius="5dip" />
          <gradient
                android:startColor="#E6E6E6"
                android:centerColor="#E6E6E6"
                android:centerY="0.75"
                android:endColor="#E6E6E6"
                android:angle="270"/>
       </shape>
      </item>
      <item android:id="@android:id/progress">   //----this is progress status
       <clip>
       <shape>
          <gradient
                android:startColor="#FF0040"
                android:centerColor="#FFFF00"
                android:endColor="#00FF00"
                android:angle="0" />            //-This varies colors linearly
       </shape>
       </clip>
      </item>
    </layer-list>
    
    0 讨论(0)
  • 2021-01-23 16:41

    The R class is generated by Android compiler, all fields of the inner class in R.java refer to the resources in res folder by android:id xml attribute. The Resouce class can retrieve the resource object by using the resource id. So, you can get Drawable object through Resource.getDrawable(int).

    0 讨论(0)
提交回复
热议问题