自定义Android SeekBar 图片 大小 等样式

系统自带的SeekBar真是太难看了,不能容忍! 只能自己做了,先来张效果图

%title插图%num

 

第1个Seekbar 背景是颜色,thumb是图片,上代码:

 

  1.     <SeekBar
  2.         android:id=“@+id/sb_detail_play_progress”
  3.         android:layout_width=“fill_parent”
  4.         android:layout_height=“wrap_content”
  5.         android:layout_centerVertical=“true”
  6.         android:layout_gravity=“center”
  7.         android:paddingLeft=“15.0dip”
  8.         android:paddingRight=“15.0dip”
  9.         android:progressDrawable=“@drawable/progress_holo_light”
  10.         android:thumb=“@drawable/detail_icon_schedule_ball” />

drawable/po_seekbar.xml:

  1. <?xml version=”1.0″ encoding=”utf-8″?>
  2. <layer-list
  3. xmlns:android=“http://schemas.android.com/apk/res/android”>
  4. <item android:id=“@*android:id/background”>
  5. <shape>
  6. <solid android:color=“#ff51495e” />
  7. </shape>
  8. </item>
  9. <item android:id=“@*android:id/secondaryProgress”>
  10. <clip>
  11. <shape>
  12. <solid android:color=“#ff51495e” />
  13. </shape>
  14. </clip>
  15. </item>
  16. <item android:id=“@*android:id/progress”>
  17. <clip>
  18. <shape>
  19. <solid android:color=“#ff996dfe” />
  20. </shape>
  21. </clip>
  22. </item>
  23. </layer-list>
  1.  

drawable/seekbar_thumb.xml:

  1.  <?xml version=”1.0″ encoding=”utf-8″?>
  2. <selector
  3. xmlns:android=“http://schemas.android.com/apk/res/android”>
  4. <item android:state_focused=“true” android:state_pressed=“false” android:drawable=“@drawable/seekbar_thumb_normal” />
  5. <item android:state_focused=“true” android:state_pressed=“true” android:drawable=“@drawable/seekbar_thumb_pressed” />
  6. <item android:state_focused=“false” android:state_pressed=“true” android:drawable=“@drawable/seekbar_thumb_pressed” />
  7. <item android:drawable=“@drawable/seekbar_thumb_normal” />
  8. </selector>
  1. 改变大小
  2. 如何改变seekbar的厚度呢,是没有属性能直接修改的,得通过重新定义样式:

     

     
  3. <SeekBar
  4. android:layout_width="match_parent"
  5. android:layout_height="wrap_content"
  6. android:layout_marginTop="20dp"
  7. android:thumb="@drawable/seek"
  8. android:progressDrawable="@drawable/seek_style"
  9. />
  10.  
  11. <?xml version="1.0" encoding="utf-8"?>
  12. <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
  13. <size
  14. android:width="20dp"
  15. android:height="20dp"
  16. />
  17. <solid android:color="#60f0"/>
  18. </shape>
  19. progressDrawable 修改进度条的样式: 
     
  20. <?xml version="1.0" encoding="utf-8"?>
  21. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  22. <item android:id="@android:id/background">
  23. <shape>
  24. <solid android:color="#999"/>
  25. </shape>
  26. </item>
  27. <item android:id="@android:id/secondaryProgress">
  28. <clip>
  29. <shape>
  30. <corners android:radius="5dip" />
  31. <gradient
  32. android:startColor="#80ffd300"
  33. android:centerColor="#80ffb600"
  34. android:centerY="0.75"
  35. android:endColor="#a0ffcb00"
  36. android:angle="270"
  37. />
  38. </shape>
  39. </clip>
  40. </item>
  41. <item android:id="@android:id/progress">
  42. <clip>
  43. <shape>
  44. <solid android:color="#600f"/>
  45. </shape>
  46. </clip>
  47. </item>
  48. thumb 修改可拖拽的圆的样式: