1、在drawable目录下新建XML文件progressbar_horizontal_red:
[java]view plaincopy<?xmlversion="1.0"encoding="utf-8"?> <!-- Copyright(C)TheAndroidOpenSourceProjectLicensedunderthe ApacheLicense,Version2.0(the"License");youmaynotusethisfile exceptincompliancewiththeLicense.Youmayobtainacopyofthe Licenseat/licenses/LICENSE-2.0Unlessrequired byapplicablelaworagreedtoinwriting,softwaredistributedunder theLicenseisdistributedonan"ASIS"BASIS,WITHOUTWARRANTIESOR CONDITIONSOFANYKIND,eitherexpressorimplied.SeetheLicensefor thespecificlanguagegoverningpermissionsandlimitationsunderthe License. --> <layer-listxmlns:android="/apk/res/android"> <itemandroid:id="@android:id/background"> <shape> <cornersandroid:radius="5dip"/> <gradientandroid:startColor="#ff333333" android:centerColor="#ff4a4a4a"android:centerY="0.75" android:endColor="#ff333333"android:angle="270"/> </shape> </item> <itemandroid:id="@android:id/secondaryProgress"> <clip> <shape> <cornersandroid:radius="5dip"/> <gradientandroid:startColor="#8000AADD" android:centerColor="#8000AADD"android:centerY="0.75" android:endColor="#8000AADD"android:angle="270"/> </shape> </clip> </item> <itemandroid:id="@android:id/progress"> <clip> <shape> <cornersandroid:radius="5dip"/> <gradientandroid:startColor="#fffa6b6b" android:centerColor="#ffff0000"android:centerY="0.75" android:endColor="#ffe80202"android:angle="270"/> </shape> </clip> </item> </layer-list>
2、在values目录下新建XML文件styles:
[java]view plaincopy<?xmlversion="1.0"encoding="utf-8"?> <resources> <stylename="progressbarStyle_Horizontal_Red"parent="android:Widget.ProgressBar.Horizontal"> <itemname="android:indeterminateOnly">false</item> <itemname="android:progressDrawable">@drawable/progressbar_horizontal_red</item> <itemname="android:minHeight">12.0dp</item> <itemname="android:maxHeight">12.0dp</item> </style> </resources>
3、布局文件代码:
[java]view plaincopy<ProgressBar android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/progressbarStyle_Horizontal_Red"/>
运行起来之后可以发现水平进度条已经变成红色的了~