android SeekBar 樣式設置(包含自定義樣式)



  UI參考

 

 

 

 

 

 

 



 
 

 

Xml代碼  收藏代碼
  1. <SeekBar  
  2.        android:id="@+id/seekbar"  
  3.        style="?android:attr/progressBarStyleHorizontal"  
  4.        android:layout_width="fill_parent"  
  5.        android:layout_height="wrap_content"  
  6.        android:progressDrawable="@layout/seekbar_style"  
  7.        android:thumb="@layout/thumb" />  

 

 

方式一:通過背景圖片設置實現

seekbar_style.xml

 

Xml代碼  收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.     <!-- 背景項 -->  
  4.     <item android:id="@android:id/background">  
  5.         <!-- 背景圖 :這裏使用9文件,因此這麼配置,  
  6.         如果使用的是普通圖片可直接使用<drawable />標籤,或者使用<shape />標籤,自定義圖形 -->  
  7.         <nine-patch android:src="@drawable/skin_bg" />  
  8.     </item>  
  9.     <!-- 進度圖 -->  
  10.     <item android:id="@android:id/progress">  
  11.      <clip >  
  12.             <nine-patch android:src="@drawable/skin_bg2" />  
  13.      </clip>  
  14.      </item>  
  15. </layer-list>  

 

thumb.xml

Xml代碼  收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <!-- seekbar的滑塊樣式 -->  
  4.     <!-- 按下狀態 -->  
  5.     <item android:drawable="@drawable/menu_bg" android:state_pressed="true"/>  
  6.     <!-- 普通無焦點狀態 -->  
  7.     <item android:drawable="@drawable/menu_bg" android:state_focused="false" android:state_pressed="false"/>  
  8.   
  9. </selector>  

 

 

 

方式二:通過<shape  />標籤爲SeekBar設置背景和進度的xml配置文件

seekbar_style.xml

 

Xml代碼  收藏代碼
  1. <?xml version="1.0" encoding="utf-8"?>     
  2. <!-- ChenJianLi Code: View: Seekbar      
  3.         滑動時的背景效果 -->     
  4.     
  5. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">     
  6.   <!--  背景  -->     
  7.     <item android:id="@android:id/background">     
  8.         <shape>     
  9.             <corners android:radius="5dip" />     
  10.             <gradient     
  11.                     android:startColor="#ffffffff"    
  12.                     android:centerColor="#fffffff0"    
  13.                     android:centerY="0.75"    
  14.                     android:endColor="#fffffafa"    
  15.                     android:angle="270"    
  16.             />     
  17.         </shape>     
  18.     </item>     
  19.     <!--  第二進度條  -->     
  20.     <item android:id="@android:id/secondaryProgress">     
  21.         <clip>     
  22.             <shape>     
  23.                 <corners android:radius="5dip" />     
  24.                 <gradient     
  25.                         android:startColor="#8000cdcd"    
  26.                         android:centerColor="#8000bfff"    
  27.                         android:centerY="0.75"    
  28.                         android:endColor="#a000b2ee"    
  29.                         android:angle="270"    
  30.                 />     
  31.             </shape>     
  32.         </clip>     
  33.     </item>     
  34.     <!--  第一進度條  -->     
  35.     <item android:id="@android:id/progress">     
  36.         <clip>     
  37.             <shape>     
  38.                 <corners android:radius="5dip" />     
  39.                 <gradient     
  40.                         android:startColor="#ff00ffff"    
  41.                         android:centerColor="#ff00ced1"    
  42.                         android:centerY="0.75"    
  43.                         android:endColor="#ff00f5ff"    
  44.                         android:angle="270"    
  45.                 />     
  46.             </shape>     
  47.         </clip>     
  48.     </item>     

 方式三:

Xml代碼  收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.   
  4.     <!-- 使用<drawable />標籤設置背景圖片 -->  
  5.     <!-- 背景項 -->  
  6.   
  7.     <item  
  8.         android:id="@android:id/background"  
  9.         android:drawable="@drawable/timeline1"></item>  
  10.     <!-- 進度圖 -->  
  11.   
  12.     <item  
  13.         android:id="@android:id/progress"  
  14.         android:drawable="@drawable/timeline2"></item>  
  15.   
  16. </layer-list>  

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章