ProgressBar 顏色的設定

Main-zy發表於2014-08-27

轉載自:http://blog.csdn.net/mars2639/article/details/6620836

佈局檔案程式碼:

[html] view plaincopy
  1. <ProgressBar   
  2.                 android:id="@+id/progressbar"  
  3.                 android:layout_width="wrap_content"  
  4.                 android:layout_height="wrap_content"  
  5.                 android:indeterminateDrawable="@drawable/progressbar"  
  6.             />  

此XML檔案新建在drawable目錄下:檔名為:progressbar

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <animated-rotate  
  3.    xmlns:android="http://schemas.android.com/apk/res/android"  
  4.  android:pivotX="50%" android:pivotY="50%"      
  5.  android:fromDegrees="0"    
  6.  android:toDegrees="360">  
  7.       
  8.     <shape   
  9.      android:shape="ring"   
  10.      android:innerRadiusRatio="3"    
  11.   android:thicknessRatio="8"   
  12.   android:useLevel="false">    
  13.   <gradient   
  14.    android:type="sweep"   
  15.    android:useLevel="false"    
  16.    android:startColor="#6BD3FF"           
  17.     android:centerColor="#FF7121"    
  18.    android:centerY="0.50"   
  19.    android:endColor="#FFFF00" />    
  20.  </shape>    
  21.       
  22. </animated-rotate>  



至於設定水平進度條的顏色:

[html] view plaincopy
  1. <LinearLayout android:gravity="center"  
  2.     android:orientation="horizontal"  
  3.     android:padding="10dp"   
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="wrap_content">  
  6.     <SeekBar android:layout_gravity="center" android:id="@android:id/progress"  
  7.         android:paddingLeft="8.0dip" android:paddingRight="8.0dip"  
  8.         android:paddingBottom="4.0dip" android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content" android:maxHeight="2.0px"  
  10.         android:progressDrawable="@drawable/progressbar_drawable" android:minHeight="2.0px"  
  11.         android:thumb="@drawable/seekbar_thumb" style="?android:attr/progressBarStyleHorizontal" />  
  12. </LinearLayout>  

progressbar_drawable.xml如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <item android:id="@android:id/background">  
  4.         <shape>  
  5.             <corners android:radius="2.0dip" />  
  6.             <gradient android:startColor="#ff000000" android:centerColor="#ff000000" android:endColor="#ff000000" android:angle="270.0" android:centerY="2.0"  />  
  7.         </shape>  
  8.     </item>  
  9.     <item android:id="@android:id/progress">  
  10.         <clip>  
  11.             <shape>  
  12.                 <corners android:radius="2.0dip" />  
  13.                 <gradient android:startColor="#ff33b5e5" android:centerColor="#ff33b5e5" android:endColor="#ff33b5e5" android:angle="270.0" android:centerY="2.0"  />  
  14.             </shape>  
  15.         </clip>  
  16.     </item>  
  17. </layer-list>  

相關文章