系统自带的SeekBar真是太难看了,项目需要,只能自定义了,先来张效果图
第一个Seekbar 背景是颜色,thumb是图片,上代码:
- <SeekBar
- android:id="@+id/timeline"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:focusable="true"
- android:maxHeight="4.0dip"
- android:minHeight="4.0dip"
- android:paddingLeft="16.0dip"
- android:paddingRight="16.0dip"
- android:progressDrawable="@drawable/po_seekbar"
- android:thumb="@drawable/seekbar_thumb" />
- <?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>
- <solid android:color="#ff51495e" />
- </shape>
- </item>
- <item android:id="@*android:id/secondaryProgress">
- <clip>
- <shape>
- <solid android:color="#ff51495e" />
- </shape>
- </clip>
- </item>
- <item android:id="@*android:id/progress">
- <clip>
- <shape>
- <solid android:color="#ff996dfe" />
- </shape>
- </clip>
- </item>
- </layer-list>
- <?xml version="1.0" encoding="utf-8"?>
- <selector
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/seekbar_thumb_normal" />
- <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/seekbar_thumb_pressed" />
- <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/seekbar_thumb_pressed" />
- <item android:drawable="@drawable/seekbar_thumb_normal" />
- </selector>
seekbar_thumb_pressed.png:
seekbar_thumb_normal.png:
第2个和第3个seekbar都是图片实现的
- <SeekBar
- android:id="@+id/sb_detail_play_progress"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_gravity="center"
- android:paddingLeft="15.0dip"
- android:paddingRight="15.0dip"
- android:progressDrawable="@drawable/progress_holo_light"
- android:thumb="@drawable/detail_icon_schedule_ball" />
drawable/progress_holo_light.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" android:drawable="@drawable/volumn_bg" />
- <item android:id="@*android:id/secondaryProgress">
- <scale android:drawable="@drawable/volumn_front" android:scaleWidth="100%" />
- </item>
- <item android:id="@*android:id/progress">
- <scale android:drawable="@drawable/volumn_primary" android:scaleWidth="100%" />
- </item>
- </layer-list>
volumn_front.9.png
volumn_primary.png
第3个seekbar
这有个图片