RatingBar主题在Marshmallow工作但不在Lollipop工作

时间:2016-10-07 06:49:47

标签: android android-styles ratingbar

我正在尝试使用以下代码设置我的RatingBar样式:

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

在layout.xml中我使用以下代码:

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

它在Marshmallow工作正常(查看截图) enter image description here

但在棒棒糖主题不起作用(查看截图) enter image description here

请帮助...... !!!!

1 个答案:

答案 0 :(得分:5)

经过多次努力,我得到了答案: 它应该是style="@style/RatingBarfeed"而不是android:theme+"@style/RatingBarfeed"

用于样式星形填充,空白和部分颜色

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

最终代码应该像

 <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 name="RatingBarfeed" parent="android:style/Widget.Material.RatingBar.Small">
    <item name="colorControlNormal">@color/white</item>
    <item name="colorControlActivated">@color/duskYellow</item>
</style>