實現的目標:
1.自定義SeekBar背景
android:progressDrawable="@drawable/seekbar_bg"
<?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>
<size android:height="1dp" />
<corners android:radius="0.5dp" />
<gradient
android:endColor="@color/standard_black_fourth_level_color_c6"
android:startColor="@color/standard_black_fourth_level_color_c6" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<size android:height="3dp" />
<corners android:radius="1.5dp" />
<gradient
android:endColor="@color/standard_red_main_color_c1"
android:startColor="@color/standard_red_main_color_c1" />
</shape>
</clip>
</item>
</layer-list>
2.自定義滑塊
android:thumb="@drawable/seekbar_thumb"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/seekbar_round_bg" android:state_pressed="true"/>
<item android:drawable="@drawable/seekbar_round_bg" android:state_focused="true"/>
<item android:drawable="@drawable/seekbar_round_bg"></item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/standard_red_main_color_c1" />
<size android:width="15dp" android:height="15dp" />
</shape>
3.整個SeekBar佈局
<SeekBar android:id="@+id/read_setting_sb_brightness" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1.0" android:max="100" android:maxHeight="3dp" android:minHeight="3dp" android:duplicateParentState="false" android:splitTrack="false" android:progressDrawable="@drawable/seekbar_bg" android:thumb="@drawable/seekbar_thumb" android:thumbOffset="10dp"/>
4.填坑
4.1SeekBar自帶有一定的padingLef和padingRight。如果你把這兩個值設置爲0了,那麼將導致滑塊無法完全顯示。
此時,我們可以不設置padingLef和padingRight,將thumbOffset設置一定的值即可。
4.2 SeekBar自帶光圈
設置SeekBar滑動事件後,點擊附近其他的佈局,居然會導致SeekBar顯示光圈,服!
設置android:duplicateParentState="false",
然後將父佈局設置:
android:focusable="true" android:focusableInTouchMode="true"