设置progressbar进度条颜色

来源:互联网 发布:龙卷风流量软件 编辑:程序博客网 时间:2024/05/18 01:05

1、在drawable目录下新建XML文件progressbar_horizontal_red:

[java] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.     <!--  
  3.         Copyright (C) 2008 The Android Open Source Project Licensed under the  
  4.         Apache License, Version 2.0 (the "License"); you may not use this file  
  5.         except in compliance with the License. You may obtain a copy of the  
  6.         License at http://www.apache.org/licenses/LICENSE-2.0 Unless required  
  7.         by applicable law or agreed to in writing, software distributed under  
  8.         the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  
  9.         CONDITIONS OF ANY KIND, either express or implied. See the License for  
  10.         the specific language governing permissions and limitations under the  
  11.         License.  
  12.     -->  
  13.   
  14. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">  
  15.   
  16.     <item android:id="@android:id/background">  
  17.         <shape>  
  18.             <corners android:radius="5dip" />  
  19.             <gradient android:startColor="#ff333333"  
  20.                 android:centerColor="#ff4a4a4a" android:centerY="0.75"  
  21.                 android:endColor="#ff333333" android:angle="270" />  
  22.         </shape>  
  23.     </item>  
  24.   
  25.     <item android:id="@android:id/secondaryProgress">  
  26.         <clip>  
  27.             <shape>  
  28.                 <corners android:radius="5dip" />  
  29.                 <gradient android:startColor="#8000AADD"  
  30.                     android:centerColor="#8000AADD" android:centerY="0.75"  
  31.                     android:endColor="#8000AADD" android:angle="270" />  
  32.             </shape>  
  33.         </clip>  
  34.     </item>  
  35.   
  36.     <item android:id="@android:id/progress">  
  37.         <clip>  
  38.             <shape>  
  39.                 <corners android:radius="5dip" />  
  40.                 <gradient android:startColor="#fffa6b6b"  
  41.                     android:centerColor="#ffff0000" android:centerY="0.75"  
  42.                     android:endColor="#ffe80202" android:angle="270" />  
  43.             </shape>  
  44.         </clip>  
  45.     </item>  
  46.   
  47. </layer-list>  


2、在values目录下新建XML文件styles:
[java] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>   
  3.    <style name="progressbarStyle_Horizontal_Red" parent="android:Widget.ProgressBar.Horizontal">  
  4.         <item name="android:indeterminateOnly">false</item>  
  5.         <item name="android:progressDrawable">@drawable/progressbar_horizontal_red</item>  
  6.         <item name="android:minHeight">12.0dp</item>  
  7.         <item name="android:maxHeight">12.0dp</item>  
  8.     </style>  
  9. </resources>  


3、布局文件代码:
[java] view plaincopy
  1. <ProgressBar  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="wrap_content"  
  4.     style="@style/progressbarStyle_Horizontal_Red" />  

运行起来之后可以发现水平进度条已经变成红色的了~
原创粉丝点击