可以通過xml文件來設置,方法如下:
1:先在布局文件中的ProgressBar加入下面屬性:
android:progressDrawable="@drawable/progress_bar"
其中progress_bar是你用於設置進度條顏色的xml文件的名字(你當然可以起一個你喜歡的名字)
2:在res資源文件中的drawable文件中新建上面的xml文件,新建的時候選則根元素為layer-list。如下圖:
3:新建完成后打開該布局文件。
引入下面代碼,設置背景色,該代碼引用自:
http://www.pocketdigi.com/20110706/363.html
<?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> <corners android:radius="5.0dip" /> <gradient android:startColor="#656666" android:endColor="#dbdedf" android:angle="270.0" android:centerY="0.75" android:centerColor="#bbbbbc" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="8.0dip" /> <gradient android:startColor="#e71a5e" android:endColor="#6c213a" android:angle="90.0" android:centerY="0.75" android:centerColor="#ac6079" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="8.0dip" /> <gradient android:startColor="#464647" android:endColor="#2d9ae7" android:angle="270.0" /> </shape> </clip> </item> </layer-list>