Rahul Sharma Rahul Sharma - 1 month ago 32
Android Question

RatingBar Theme working in Marshmallow but not in Lollipop

I am trying to style my RatingBar with the following code:

<style name="RatingBarfeed" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">@color/white</item>
<item name="colorControlActivated">@color/duskYellow</item>
</style>


And in layout.xml I am using the following code:

<android.support.v7.widget.AppCompatRatingBar
android:theme="@style/RatingBarfeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:id="@+id/ratingBar"
android:paddingBottom="0.45dp"
app:layout_constraintTop_toTopOf="@+id/rating"
app:layout_constraintLeft_toRightOf="@+id/rating"
app:layout_constraintBottom_toBottomOf="@+id/rating"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:background="@color/orange"
android:rating="3.5"
android:stepSize="0.5"/>


Its working fine in Marshmallow (check the screenshot)
enter image description here

But in Lollipop Theme is not working (check the screenshot)
enter image description here

Please Help...!!!!

Answer

After much struggle I got my answer: it should be style="@style/RatingBarfeed" instead of android:theme+"@style/RatingBarfeed"

For styling star fill, empty and partial color

android:progressTint="#F9BB28"
android:progressBackgroundTint="@color/white"
android:secondaryProgressTint="@color/white"

Final code should be like

 <android.support.v7.widget.AppCompatRatingBar
        android:layout_width="wrap_content"
        android:layout_height="18dp"
        style="@style/RatingBarfeed"
        android:id="@+id/ratingBar"
        android:gravity="center"
        android:progressTint="#F9BB28"
        android:progressBackgroundTint="@color/white"
        android:secondaryProgressTint="@color/white"
        app:layout_constraintTop_toTopOf="@+id/rating"
        app:layout_constraintLeft_toRightOf="@+id/rating"
        app:layout_constraintBottom_toBottomOf="@+id/rating"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        android:background="@color/orange"
        android:rating="3.5"
        android:stepSize="0.1"/>

Style should be:

<style name="RatingBarfeed" parent="android:style/Widget.Material.RatingBar.Small">
    <item name="colorControlNormal">@color/white</item>
    <item name="colorControlActivated">@color/duskYellow</item>
</style>
Comments