安卓系统在更多的时候需要对其颜色进行自定义,自定义progressbar样式。
在drawable目录下新增progressbar.xml文件,可以设置默认背景色和进度条的颜色
xml自定义文件中代码:
- <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="0"
- android:centerColor="#ff5a5d5a"
- android:centerY="0.75"
- android:endColor="#ff747674"
- android:startColor="#ff9d9e9d" />
- </shape>
- </item>
- <item android:id="@android:id/secondaryProgress">
- <clip>
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:angle="0"
- 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="0"
- android:endColor="#8000ff00"
- android:startColor="#80ff0000" />
- </shape>
- </clip>
- </item>
- </layer-list>
布局文件中使用如下:
- <ProgressBar
- android:id="@+id/progressBar"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="fill_parent"
- android:layout_height="7.5dp"
- android:max="100"
- android:progress="80"
- android:layout_marginRight="8dp"
- android:progressDrawable="@drawable/progressbar"
- android:visibility="visible"/>