ProgressBar、SeekBar、RatingBar 自定义样式

RatingBar:小星星风格
 style="?android:attr/ratingBarStyleSmall"

 将星星替换成别的图标:
 1)共四张图片:填满的“星星”和未填满的“星星”的选中和未选中状态
 2)新建xml文件:
  <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

       <item  // 未填满的星星selector
           android:id="@+android:id/background"
           android:drawable="@drawable/ratingbar_full_empty_holo_light"/>
       <item  // 未填满的星星selector 第二进度
           android:id="@+android:id/secondaryProgress"
           android:drawable="@drawable/ratingbar_full_empty_holo_light"/>
       <item // 填满的星星 selector 第一进度
           android:id="@+android:id/progress"
           android:drawable="@drawable/ratingbar_full_filled_holo_light"/>
  </layer-list>

 3)未填满星星的两种状态的selector:
  <selector xmlns:android="http://schemas.android.com/apk/res/android">

       <item android:drawable="@drawable/btn_rating_star_off_pressed_holo_light"
    android:state_pressed="true"
    android:state_window_focused="true"/>
       <item android:drawable="@drawable/btn_rating_star_off_normal_holo_light"/>
  </selector>

 4)填满星星的两种状态的selector:
  <selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/btn_rating_star_off_pressed_holo_light"
    android:state_pressed="true"
    android:state_window_focused="true"/>
       <item android:drawable="@drawable/btn_rating_star_off_normal_holo_light"/>
  </selector>
 5)设置ProgressDrawable属性。

ProgressBar:
 共有三个颜色:底色、第二进度颜色、主要进度颜色
 1)新建xml文件 custompb.xml
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">


  <item android:id="@android:id/background"
               

   android:drawable="@android:drawable/progress_bg_holo_dark" /> // 底色图片
  <item android:id="@android:id/secondaryProgress">
   <scale android:scaleWidth="100%"
                     

   android:drawable="@android:drawable/progress_secondary_holo_dark" /> // 第二进度图片
  </item>
  <item android:id="@android:id/progress">
   <scale android:scaleWidth="100%"
   android:drawable="@android:drawable/progress_primary_holo_dark" /> // 主要进度图片
  </item>
 

</layer-list>

 2)准备三个经过处理的 .9 图片。

 3)在布局文件的ProgressBar节点中添加属性:
  progressDrawable = "@drawable/custompb"

SeekBar:
 进度条属性,与 ProgressBar 的xml文件一样
  android:progressDrawable="@drawable/scrubber_progress_horizontal_holo_light"
 拖动按钮图片属性:
  android:thumb="@drawable/scrubber_control_selector_holo"
  
  <selector xmlns:android="http://schemas.android.com/apk/res/android">

   
   // 不可用状态下显示的图标
   <item android:state_enabled="false"   
    android:drawable="@android:drawable/scrubber_control_disabled_holo" />


   // 按下状态下显示的图标
   <item android:state_pressed="true"    
    android:drawable="@android:drawable/scrubber_control_pressed_holo" />
   

   // 选中状态下的图标
   <item android:state_selected="true"
    android:drawable="@android:drawable/scrubber_control_focused_holo" />
   

   // 普通无动作状态下的图标
   <item android:drawable="@android:drawable/scrubber_control_normal_holo" />

  </selector>

 可以只选择 state_pressed 状态和 无动作状态。

转载于:https://www.cnblogs.com/until-dead/p/3612531.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值