自定義RatingBar – Android移動開發技術文章_手機開發 Android移動開發教學課程

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" />

發佈留言