How to create Custom RatingBar Android Programming Tutorial

If you do not want Default RatingBar implementation then you can customize it by creating your own layouts and styles for it.

You need to get 3-star images to be added to your drawable folder.

1. A Empty (off) star image.
2. A Half Filled Star image.
3. A Fully Filled Star image.

Now create a custom XML for RatingBar in Drawable folder,

<?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/star_blank"/>
    <item
        android:id="@+android:id/secondaryProgress"
        android:drawable="@drawable/star_blank"/>
    <item
        android:id="@+android:id/progress"
        android:drawable="@drawable/star_filled"/>

</layer-list>

start_blank.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/star_off" 
          android:state_pressed="true" 
          android:state_window_focused="true"/>

    <item android:drawable="@drawable/star_off" 
          android:state_focused="true" 
          android:state_window_focused="true"/>

    <item android:drawable="@drawable/star_off" 
          android:state_selected="true" 
          android:state_window_focused="true"/>


    <item android:drawable="@drawable/star_off"/>

</selector>

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!