自定义水平进度条(颜色)

来源:互联网 发布:网络游戏音乐大全 编辑:程序博客网 时间:2024/06/04 04:16

一、1.在资源文件styles里面创建一个style:

         

 <style name="ProgressBar_red_gray" parent="@android:style/Widget.ProgressBar.Horizontal">        <item name="android:progressDrawable">@drawable/progress_horizontal_red_gray</item> </style>
        progress_horizontal_red_gray为一个layer-list资源,内容如下:

<?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="5dip" />            <gradient                android:angle="270"                android:centerColor="#ffcccccc"                android:centerY="0.75"                android:endColor="#ffcccccc"                android:startColor="#ffcccccc" />        </shape>    </item>    <item android:id="@android:id/secondaryProgress">        <clip>            <shape>                <corners android:radius="5dip" />                <gradient                    android:angle="270"                    android:centerColor="#80ffb600"                    android:centerY="0.75"                    android:endColor="#a0ffcb00"                    android:startColor="#80ffd300" />            </shape>        </clip>    </item>    <item android:id="@android:id/progress">        <clip>            <shape>                <corners android:radius="5dip" />                <gradient                    android:angle="270"                    android:centerColor="#ffDE2632"                    android:centerY="0.75"                    android:endColor="#ffDE2632"                    android:startColor="#ffDE2632" />            </shape>        </clip>    </item></layer-list>
shape可以自定义,<clip>标签不能去掉

2.在布局文件设置ProgressBar的style为ProgressBar_red_gray即可,如下:

<ProgressBar        android:id="@+id/pgb_support_percent"        style="@style/progress_horizontal_red_gray"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:max="100"        android:progress="5" />



二、首先如上创建drawable资源  progress_horizontal_red_gray,然后在在布局文件设置ProgressBar的android:progressDrawable属性为progress_horizontal_red_gray,如下:

<ProgressBar        android:id="@+id/pgb_support_percent"        style="@android:style/Widget.ProgressBar.Horizontal"        android:progressDrawable="@drawable/progress_horizontal_red_gray"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:max="100"        android:progress="5" />



        


0 0
原创粉丝点击