Android RatingBar 评分设置不正确
Android RatingBar rating is not set correctly
我在 xml 布局中使用了两个 RatingBar:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.25"
android:rating="4.25"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.25"
android:rating="4.5"/>
尽管我将评分设置为 4.25 和 4.5,但两个 RatingBars 都显示了错误的星星数。在 Android 6 设备上,它看起来像这样:
在 android 4.3 设备上,它看起来像这样:
但是在 xml 设计视图中,我可以看到设置了 4.25 和 4.5。谁能告诉我为什么?我没有对代码中的评级栏进行任何操作。
谢谢。
我认为问题与 android:progressTint ,android:progressBackgroundTint & android:secondaryProgressTint
有关。
尝试将以下行添加到您的评分栏:
android:progressTint="Color1"
android:progressBackgroundTint="Color2"
android:secondaryProgressTint="Color3"
也尝试为您的评分栏添加如下样式:
<style name="RatingBar" parent="Theme.AppCompat"">
<item name="colorControlNormal">@color/yourColor1</item>
<item name="colorControlActivated">@color/yourColor2</item></style>
最后在您的评分栏中添加以下行
style="@style/RatingBar"
它会为你工作。
我在 xml 布局中使用了两个 RatingBar:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.25"
android:rating="4.25"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.25"
android:rating="4.5"/>
尽管我将评分设置为 4.25 和 4.5,但两个 RatingBars 都显示了错误的星星数。在 Android 6 设备上,它看起来像这样:
在 android 4.3 设备上,它看起来像这样:
但是在 xml 设计视图中,我可以看到设置了 4.25 和 4.5。谁能告诉我为什么?我没有对代码中的评级栏进行任何操作。
谢谢。
我认为问题与 android:progressTint ,android:progressBackgroundTint & android:secondaryProgressTint
有关。
尝试将以下行添加到您的评分栏:
android:progressTint="Color1"
android:progressBackgroundTint="Color2"
android:secondaryProgressTint="Color3"
也尝试为您的评分栏添加如下样式:
<style name="RatingBar" parent="Theme.AppCompat"">
<item name="colorControlNormal">@color/yourColor1</item>
<item name="colorControlActivated">@color/yourColor2</item></style>
最后在您的评分栏中添加以下行
style="@style/RatingBar"
它会为你工作。