如何修改SeekBar的样式

自定义SeekBar样式
谷歌是怎么定义的?
<SeekBar
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
style=”@android:style/Widget.SeekBar”/>

谷歌定义的SeekBar的样式全在@android:style/Widget.SeekBar中,通过样式可以观察发现谷歌是如何定义SeekBar的。可以通过修改样式,覆盖原来样式,从而达到我们需要的效果。

<style name=”Widget.SeekBar”>
<item name=”indeterminateOnly”>false</item>
<!–progressDrawable定义了背景图,进度图,和缓冲图–>
<item name=”progressDrawable”>@drawable/progress_horizontal</item>
<item name=”indeterminateDrawable”>@drawable/progress_horizontal</item>
<item name=”minHeight”>20dip</item>
<item name=”maxHeight”>20dip</item>
<!–thumb定义了滑块的图片–>
<item name=”thumb”>@drawable/seek_thumb</item>
<item name=”thumbOffset”>8dip</item>
<item name=”focusable”>true</item>
<item name=”mirrorForRtl”>true</item>
</style>

如果想改变SeekBar的背景图,进度图,和缓存图等,我们可以自定义progressDrawable,例如
progress_horizotal.xml

<layer-list xmlns:android=”http://schemas.android.com/apk/res/android”>
<!–这是SeekBar的背景图–>
<item android:id=”@android:id/background” android:drawable=”@drawable/seekbar_background”>
</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>
<!–这是SeekBar的进度图–>
<item android:id=”@android:id/progress”>
<clip>
<shape>
<corners android:radius=”5dip” />
<solid android:color=”@color/blue”/>
</shape>
</clip>
</item>

</layer-list>

然后在定义SeekBar的时候可以这样使用:

<SeekBar
style=”@android:style/Widget.SeekBar”
<!–覆盖原来进度的样式–> android:progressDrawable=”@drawable/progress_horizotal”
<!–覆盖滑块的样式–>
android:thumb=”@drawable/seekbar_thumb”
android:minHeight=”3dp”
android:maxHeight=”3dp”
android:max=”100″
android:progress=”50″
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:layout_marginLeft=”4dp”
android:layout_marginRight=”4dp”/>
————————————————