Android下修改SeekBar样式

SeekBar配置文件:

Xml代码
  1. <SeekBar
  2. android:id="@+id/player_seekbar"
  3. android:layout_width="245px"
  4. android:layout_height="25px"
  5. android:progressDrawable="@drawable/seekbar_style"
  6. android:thumb="@drawable/thumb"
  7. android:paddingLeft="16px"
  8. android:paddingRight="15px"
  9. android:paddingTop="5px"
  10. android:paddingBottom="5px"
  11. android:progress="0"
  12. android:max="0"
  13. android:secondaryProgress="0"
  14. />
<SeekBar 
       android:id="@+id/player_seekbar"
       android:layout_width="245px"
       android:layout_height="25px"
       android:progressDrawable="@drawable/seekbar_style"
       android:thumb="@drawable/thumb"
       android:paddingLeft="16px"
       android:paddingRight="15px"
       android:paddingTop="5px"
          android:paddingBottom="5px"
          android:progress="0"
          android:max="0"
          android:secondaryProgress="0"
          />

android:progressDrawable="@drawable/seekbar_style"背景条

seekbar_style配置如下:

Xml代码
  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="5dip" />
  6. <gradient
  7. android:startColor="#ff9d9e9d"
  8. android:centerColor="#ff5a5d5a"
  9. android:centerY="0.75"
  10. android:endColor="#ff747674"
  11. android:angle="270"
  12. />
  13. </shape>
  14. </item>
  15. <item android:id="@android:id/secondaryProgress">
  16. <clip>
  17. <shape>
  18. <corners android:radius="5dip" />
  19. <gradient
  20. android:startColor="#80ffd300"
  21. android:centerColor="#80ffb600"
  22. android:centerY="0.75"
  23. android:endColor="#a0ffcb00"
  24. android:angle="270"
  25. />
  26. </shape>
  27. </clip>
  28. </item>
  29. <item android:id="@android:id/progress">
  30. <clip>
  31. <shape>
  32. <corners android:radius="5dip" />
  33. <gradient
  34. android:startColor="#ff0099CC"
  35. android:centerColor="#ff3399CC"
  36. android:centerY="0.75"
  37. android:endColor="#ff6699CC"
  38. android:angle="270"
  39. />
  40. </shape>
  41. </clip>
  42. </item>
  43. </layer-list>
<?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>

或者:用图片如下:

Xml代码
  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. android:drawable="@drawable/progress_bg" />
  5. <item android:id="@android:id/secondaryProgress"
  6. android:drawable="@drawable/second_progress">
  7. </item>
  8. <item android:id="@android:id/progress"
  9. android:drawable="@drawable/first_progress">
  10. </item>
  11. </layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
 <item android:id="@android:id/background" 
       android:drawable="@drawable/progress_bg" />
     
 <item android:id="@android:id/secondaryProgress"
       android:drawable="@drawable/second_progress">
 </item> 
 
 <item android:id="@android:id/progress"
       android:drawable="@drawable/first_progress">
     
 </item> 
</layer-list>

方形

Xml代码
  1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  2. <item android:id="@android:id/background"
  3. android:drawable="@drawable/progress_bg" />
  4. <item android:id="@android:id/secondaryProgress">
  5. <clip android:drawable="@drawable/second_progress" />
  6. </item>
  7. <item android:id="@android:id/progress">
  8. <clip android:drawable="@drawable/first_progress" />
  9. </item>
  10. </layer-list>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:id="@android:id/background" 
    android:drawable="@drawable/progress_bg" /> 

    <item android:id="@android:id/secondaryProgress"> 
     <clip android:drawable="@drawable/second_progress" /> 
    </item> 

    <item android:id="@android:id/progress"> 
         <clip android:drawable="@drawable/first_progress" /> 
    </item> 

</layer-list>

android:thumb="@drawable/thumb"就是那个会动的球

配置如下:

Xml代码
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  3. <!-- 按下状态-->
  4. <item
  5. android:state_focused="true"
  6. android:state_pressed="true"
  7. android:drawable="@drawable/thumb_pressed" />
  8. <!-- 普通无焦点状态 -->
  9. <item
  10. android:state_focused="false"
  11. android:state_pressed="false"
  12. android:drawable="@drawable/thumb_normal" />
  13. <!-- 有焦点状态-->
  14. <item
  15. android:state_focused="true"
  16. android:state_pressed="false"
  17. android:drawable="@drawable/thumb_focused" />
  18. <!-- 有焦点 -->
  19. <item
  20. android:state_focused="true"
  21. android:drawable="@drawable/thumb_focused" />
  22. </selector>

你可能感兴趣的:(android)