SeekBar自定义
16lz
2021-01-23
代码如下
- <SeekBarandroid:id="@android:id/progress"
- style="?android:attr/progressBarStyleHorizontal"
- android:progressDrawable="@drawable/seekbar_style"
- android:thumb="@drawable/thumb"
- android:layout_width="fill_parent"
- android:layout_height="23dip"
- android:paddingLeft="25dip"
- android:paddingRight="25dip"
- android:paddingBottom="4dip/>
其实最最关键的就是
- android:progressDrawable="@drawable/seekbar_style"
- android:thumb="@drawable/thumb"
怎么去定义呢?
看下面的代码:
seekbar_style.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <layer-listxmlns:android="http://schemas.android.com/apk/res/android">
- <itemandroid:id="@android:id/background">
- <shape>
- <cornersandroid:radius="10dip"/>
- <gradient
- android:startColor="#ffffffff"
- android:centerColor="#ff000000"
- android:endColor="#ff808A87"
- android:centerY="0.45"
- android:angle="270"/>
- </shape>
- </item>
- <itemandroid:id="@android:id/progress">
- <clip>
- <shape>
- <cornersandroid:radius="10dip"/>
- <gradient
- android:startColor="#ffffffff"
- android:centerColor="#ffFFFF00"
- android:endColor="#ffAABD00"
- android:centerY="0.45"
- android:angle="270"/>
- </shape>
- </clip>
- </item>
- </layer-list>
thumb.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <selectorxmlns:android="http://schemas.android.com/apk/res/android">
- <!--按下状态-->
- <item
- android:state_pressed="true"
- android:drawable="@drawable/xxxxxxxxxx"/>
- <!--普通无焦点状态-->
- <item
- android:state_focused="false"
- android:state_pressed="false"
- android:drawable="@drawable/xxxxxxx"/>
- 上面的xxxxxxx是图片
- </selector>
OK,问题解决!嘿嘿!
更多相关文章
- 【Android】Android 代码判断是否获取ROOT权限(一)
- android手机安全卫士、Kotlin漫画、支付宝动画、沉浸状态栏等源
- Android标题栏、状态栏、全屏
- Android隐藏状态栏和标题栏
- android:descendantFocusability 焦点 父控件与子控件焦点
- Android修改默认控件焦点不highlight
- Android中的drawable state的各种状态
- TextView碉堡了!android源代码的一些统计信息!
- SignalR实现实时Web聊天的实例代码