SeekBar介绍
SeekBar是ProgressBar的子类,通过对ProgressBar进行功能性的补充,可以响应用户的点击和拖动事件。接下来将要介绍属性设置、样式设置以及功能设置。并且通过SeekBar来控制系统音量。
SeekBar常用属性介绍
首先在xml当中对SeekBar进行属性的设置
<SeekBar
android:id="@+id/seek_bar"
style="@android:style/Widget.Material.SeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="200"
android:padding="20dp"
android:progress="0"
android:visibility="visible"
android:progressDrawable="@drawable/seek_bar_voice_bg"
android:thumb="@drawable/seek_bar_voice_circle"/>
其中,android:max是对进度条的最大值进行设定,在这里进行设置之后,还可以通过使用seekBar.setMax()函数进行设置,SeekBar的默认范围是[0,100]。
android:progress显示的是进度条的初始值,其值不能大于设置的最大值,在这里进行设置之后,还可以通过使用seekBar.setProgress()函数进行设置
android:progressDrawable=”@drawable/seek_bar_voice_bg”,对进度条的样式进行设置
android:thumb=”@drawable/seek_bar_voice_circle”,对进度条的按钮样式进行设置
SeekBar样式属性设置
首先对进度条样式进行设置,在drawable路径下,设置seek_bar_voice_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>
<solid android:color="#65686A" />
</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="#2287F