自定义漂亮的Android SeekBar样式

本文介绍了一种自定义SeekBar的方法,通过定义XML文件实现进度条背景、进度颜色等样式调整,并展示了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统自带的SeekBar真是太难看了,项目需要,只能自定义了

seek_drawable.xml

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <layer-list  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <item android:id="@android:id/background" android:drawable="@drawable/play_back" />  
  5.     <item android:id="@android:id/secondaryProgress">  
  6.         <clip android:drawable="@drawable/seek_sencond_progress" />  
  7.     </item>  
  8.     <item android:id="@android:id/progress">  
  9.         <clip android:drawable="@drawable/play_schedule" />  
  10.     </item>  
  11. </layer-list>  

seek_thumb.xml

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <item android:state_pressed="true" android:drawable="@drawable/play_slide" />  
  5.     <item android:state_pressed="false" android:drawable="@drawable/play_slide_normal" />  
  6. </selector>  

然后这样用就OK了:

[html]  view plain copy
  1. <SeekBar  
  2.     android:id="@+id/ctrl_skbProgress"  
  3.     android:layout_width="200dp"  
  4.     android:layout_height="40dp"  
  5.     android:layout_gravity="center_vertical"  
  6.     android:maxHeight="40dp"  
  7.     android:minHeight="40dp"  
  8.     android:paddingLeft="2dp"  
  9.     android:paddingRight="2dp"  
  10.     android:progressDrawable="@drawable/seek_drawable"  
  11.     android:thumb="@drawable/seek_thumb"  
  12.     android:thumbOffset="2.0dp" />  

最终的效果图:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值