我想将颜色更改为绿色。我尝试了几种方法,但都没有。
使用 android:progressTint
<RatingBar
android:id="@+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:progressTint="@color/green"
android:layout_gravity="center"/>
另一种尝试。在styles.xml中添加一个新样式:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/iron</item>
<item name="colorControlActivated">@color/green</item>
</style>
并应用它:
<RatingBar
android:id="@+id/rb"
android:theme="@style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="center"/>
我的测试设备是华硕手机,运行Android 4.4.2。还有其他方法,适用于Android 4及更新版本吗?谢谢。
答案 0 :(得分:0)
您需要在values和v21下的styles.xml文件中创建两个样式。
将此样式放在values / styles.xml文件中
<style name="RatingBar" parent="@android:style/Widget.Holo.Light.RatingBar">
<item name="colorControlNormal">@color/colorAccent</item>
<item name="colorControlActivated">@color/colorAccent</item>
</style>
将此样式放在v21 / styles.xml文件中
<style name="RatingBar" parent="android:style/Widget.Material.RatingBar">
<item name="colorControlNormal">@color/colorAccent</item>
<item name="colorControlActivated">@color/colorAccent</item>
</style>
在布局文件中,使用如下所示的样式:
<RatingBar
android:id="@+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"
style="@style/RatingBar"
android:numStars="5"
android:stepSize="1"
android:layout_gravity="center"/>
答案 1 :(得分:0)
将style="?android:attr/ratingBarStyleSmall"
替换为style="@style/RatingColor"
在styles.xml
中,添加以下内容:
<style name="RatingColor" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/blue</item>
<item name="colorControlActivated">@color/green</item>
</style>