Android中如何修改SeekBar的默认样式

SeekBar的默认样式如下:


想要修改成:(这种iphone的风格)


step1: 书写 seekbar_style.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="5dip" />  
                 <gradient  
                         android:startColor="#ff9d9e9d"  
                         android:centerColor="#ff5a5d5a"  
                         android:centerY="0.75"  
                         android:endColor="#ff747674"  
                         android:angle="270"  
                 />  
             </shape>  
         </item>  
      
         <item android:id="@android:id/secondaryProgress">  
             <clip>  
                 <shape>  
                     <corners android:radius="5dip" />  
                     <gradient  
                             android:startColor="#80ffd300"  
                             android:centerColor="#80ffb600"  
                             android:centerY="0.75"  
                             android:endColor="#a0ffcb00"  
                             android:angle="270"  
                     />  
                 </shape>  
             </clip>  
         </item>  
      
         <item android:id="@android:id/progress">  
             <clip>  
                 <shape>  
                     <corners android:radius="5dip" />  
                     <gradient  
                             android:startColor="#ff0099CC"  
                             android:centerColor="#ff3399CC"  
                             android:centerY="0.75"  
                             android:endColor="#ff6699CC"  
                             android:angle="270"  
                     />  
                 </shape>  
             </clip>  
         </item>  
      
     </layer-list>


step2: 书写 seekbar_thumb.xml  此处这个thumb 我就简化处理了,只固定使用一张图片,不管 focus, press与否

将这张图片放在 drawable-hdpi文件夹下


<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">       
        <item   
            android:drawable="@drawable/btn_circle_normal" />        
    </selector>  


step3: xml设置

  <SeekBar
             
                   android:layout_centerHorizontal="true"
                   android:progress="50"
                   android:max="100"
                   android:progressDrawable="@drawable/seekbar_style"
                   android:thumb="@drawable/seekbar_thumb"
                   />


这样就算差不多完成了。


参考资料:

http://bashenmail.iteye.com/blog/603649

http://stackoverflow.com/questions/2020882/how-to-change-progress-bars-progress-color-in-android


你可能感兴趣的:(Android中如何修改SeekBar的默认样式)