首页 > 解决方案 > 按住时带有粉红色背景的 RatingBar

问题描述

我的 RatingBar 非常规则,选择时显示如下在此处输入图像描述

但是当触摸(并握住)它们时,所有未评级的星星都是粉红色的,就像这样

在此处输入图像描述

为什么会这样?

xml:

<RatingBar
    android:id="@+id/ratingBarSchedulesRatingTour"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="4dp"
    android:numStars="5"
    android:progressTint="@color/yellow_star"
    android:secondaryProgressTint="@color/yellow_star"
    android:stepSize="1" />

@color/yellow_star 在 colors.xml 中作为 #F1CD1E

标签: androidandroid-studioratingbar

解决方案


创建您想要的样式和颜色(按/正常)

<style name="RatingBar" parent="Theme.AppCompat">
        <item name="colorControlNormal">#F1CD1E</item>
        <item name="colorControlActivated">#F1CD1E</item>
    </style>

<RatingBar
        android:id="@+id/ratingBarSchedulesRatingTour"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:numStars="5"
        android:progressTint="#F1CD1E"
        android:theme="@style/RatingBar"
        android:secondaryProgressTint="#F1CD1E"
        android:stepSize="1" />

推荐阅读