Android开发

SeekBar的样式及使用

2017-07-15  本文已影响1362人  笔墨Android

不怕跌倒,所以飞翔

现在很多短视频都会用到seekBar去调节视频进度,所以seekBar很有必要学习一下

本文的主要知识点有:

关于seekBar的样式

系统提供的样式实在是太丑了,所以一般使用seekBar的时候都会自定义样式的,关于seekBar的自定义样式,其实就是设置一个DrawableseekBar中去,设置之后效果还是可以得,所以我们下面就开始撸代码吧!

1.首先就是在布局文件中设置SeekBar的xml

 <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxHeight="3dp"
        android:minHeight="3dp"
        android:progressDrawable="@drawable/seekbar_bg"
        android:thumb="@drawable/seekbar_thumb_bg"/>

这里说明几点:

2.seekbar的背景设置也就是上面的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>
            <solid android:color="#ff51495e"/>
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <solid android:color="#f9062a"/>
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="#2db334"/>
            </shape>
        </clip>
    </item>

</layer-list>

上面就是设置三层颜色的,其中background是底色,secondaryProgress是缓冲的颜色,progress是当前进度的颜色

3.设置thumb(也就是设置拖动时、获取焦点等拖动块的颜色)就是上面themb对应的seekbar_thumb_bg

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!--获取焦点和没有按下的时候-->
    <item android:drawable="@drawable/seekbar_thumb_normal" android:state_focused="true" android:state_pressed="false"/>
    <!--获取焦点但按下的时候-->
    <item android:drawable="@drawable/seekbar_thumb_pressed" android:state_focused="true" android:state_pressed="true"/>
    <!--没有获取焦点按下的时候-->
    <item android:drawable="@drawable/seekbar_thumb_pressed" android:state_focused="false" android:state_pressed="true"/>
    <!--默认的时候-->
    <item android:drawable="@drawable/seekbar_thumb_normal"/>

</selector>
seekbar_thumb_normal.png seekbar_thumb_pressed.png

基本上就这些东西了,别觉得我颜色配的丑,我只是觉得这样明显一些哈哈!

关于seekBar的使用

其实作为android的这个空间,没有什么主要的,就是一个监听和几个设置进度的方法

1.常用方法

别的还真不知道写什么了,以后有什么不知道的在往上面添加吧!

上一篇 下一篇

猜你喜欢

热点阅读