为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>


作者:KillerLegend
出处:http://www.cnblogs.com/KillerLegend/
分享最新的资源,分享个人所得,欢迎关注我的新浪微博
新浪微博主页:ikey4u
我的个人博客:www.ikey4u.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

 
原文地址:https://www.cnblogs.com/killerlegend/p/3251283.html