为ProgressBar进度条设置颜色1

可以通过xml文件来设置,方法如下:

1:先在布局文件中的ProgressBar加入下面属性:

android:progressDrawable="@drawable/progress_bar"

其中progress_bar是你用于设置进度条颜色的xml文件的名字(你当然可以起一个你喜欢的名字)

2:在res资源文件中的drawable文件中新建上面的xml文件,新建的时候选则根元素为layer-list。如下图:

3

image

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>
posted @ 2013-08-11 14:12  KillerLegend  Views(9327)  Comments(0Edit  收藏  举报