Android 自定义seekbar 代码实现

来源:互联网 发布:上海东行网络 编辑:程序博客网 时间:2024/04/26 18:36

话不多说,先上效果图

最后效果

<!--此处添加到layout里--><SeekBar    android:id="@+id/seekBar"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_weight="1"    android:max="100"    style="@style/Widget.SeekBar.Normal"    android:minHeight="8.0dip"    android:thumbOffset="10.0dip"    android:progress="20"/>
<!--Widget.SeekBar.Normal--><!--此处添加到style.xml--><style name="Widget.SeekBar.Normal" parent="@android:style/Widget.SeekBar">        <item name="android:maxHeight">8.0dip</item>        <item name="android:indeterminateOnly">false</item>        <item name="android:indeterminateDrawable">        @android:drawable/progress_indeterminate_horizontal</item>        <item name="android:progressDrawable">@drawable/seekbar_red</item>        <item name="android:minHeight">8.0dip</item>        <item name="android:thumb">@drawable/seek_thumb</item>        <item name="android:thumbOffset">10.0dip</item>    </style>
<!--shape和selector的结合使用--><!--位置:res/drawable/文件的名称.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/seekbar_botton" />    <item android:id="@android:id/secondaryProgress">        <clip>            <shape>                <corners android:radius="2.0dip" />                <gradient                     android:startColor="#80ffd300"                     android:angle="270.0"                     android:centerY="0.75"                     android:centerColor="#80ffb600" />            </shape>        </clip>    </item>    <item android:id="@android:id/progress">        <clip android:drawable="@drawable/seekbar_top" />    </item></layer-list>

这是按钮素材,当然,这个也是可以用代码写出来。具体写法大家可以试试。
按钮

0 0
原创粉丝点击