当前位置:操作系统 > 安卓/Android >>

自定义RatingBar

1.<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
  <item name="android:progressDrawable">@drawable/food_ratingbar_full</item>
  <item name="android:minHeight">48dip</item>
    <item name="android:maxHeight">48dip</item>
</style>
</resources>

2.
<?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/food_ratingbar_full_empty" />
    <item android:id="@+android:id/secondaryProgress"
          android:drawable="@drawable/food_ratingbar_full_empty" />
    <item android:id="@+android:id/progress"
          android:drawable="@drawable/food_ratingbar_full_filled" />
</layer-list>

3.

<?xml version="1.0" encoding="utf-8"?>
<!-- This is the rating bar drawable that is used to
show a filled cookie. -->
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:state_window_focused="true"
          android:drawable="@drawable/cookie" />
    <item android:state_focused="true"
          android:state_window_focused="true"
          android:drawable="@drawable/cookie" />
    <item android:state_selected="true"
          android:state_window_focused="true"
          android:drawable="@drawable/cookie" />
    <item android:drawable="@drawable/cookie" />
</selector>

4.
<RatingBar  android:id="@+id/my_rating_bar"
   ...
   style="@style/foodRatingBar" />

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,