转载自:http://blog.csdn.net/mars2639/article/details/6620836
布局文件代码:
- <ProgressBar
- android:id="@+id/progressbar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:indeterminateDrawable="@drawable/progressbar"
- />
此XML文件新建在drawable目录下:文件名为:progressbar
- <?xml version="1.0" encoding="utf-8"?>
- <animated-rotate
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:pivotX="50%" android:pivotY="50%"
- android:fromDegrees="0"
- android:toDegrees="360">
- <shape
- android:shape="ring"
- android:innerRadiusRatio="3"
- android:thicknessRatio="8"
- android:useLevel="false">
- <gradient
- android:type="sweep"
- android:useLevel="false"
- android:startColor="#6BD3FF"
- android:centerColor="#FF7121"
- android:centerY="0.50"
- android:endColor="#FFFF00" />
- </shape>
- </animated-rotate>
至于设置水平进度条的颜色:
- <LinearLayout android:gravity="center"
- android:orientation="horizontal"
- android:padding="10dp"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <SeekBar android:layout_gravity="center" android:id="@android:id/progress"
- android:paddingLeft="8.0dip" android:paddingRight="8.0dip"
- android:paddingBottom="4.0dip" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:maxHeight="2.0px"
- android:progressDrawable="@drawable/progressbar_drawable" android:minHeight="2.0px"
- android:thumb="@drawable/seekbar_thumb" style="?android:attr/progressBarStyleHorizontal" />
- </LinearLayout>
progressbar_drawable.xml如下:
- <?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="2.0dip" />
- <gradient android:startColor="#ff000000" android:centerColor="#ff000000" android:endColor="#ff000000" android:angle="270.0" android:centerY="2.0" />
- </shape>
- </item>
- <item android:id="@android:id/progress">
- <clip>
- <shape>
- <corners android:radius="2.0dip" />
- <gradient android:startColor="#ff33b5e5" android:centerColor="#ff33b5e5" android:endColor="#ff33b5e5" android:angle="270.0" android:centerY="2.0" />
- </shape>
- </clip>
- </item>
- </layer-list>