如何使用这样的边框创建ratingBar:https://materialdoc.com/components/rating-bar/
我的ratingBar xml:
<RatingBar
android:theme="@style/RatingBar"
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="2"
android:numStars="5"
android:stepSize="1" />应用程序样式:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/colorAccent</item>
<item name="colorControlActivated">@color/colorAccent</item>
</style>这是我得到的:

使用滤色器:
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(0).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(1).setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_ATOP);

发布于 2018-01-22 22:00:49
解决方案:你可以使用自定义的抽屉来评级吧。
尝尝这个
XML代码
<RatingBar
android:id="@+id/ratingBar"
style="@style/MyRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:stepSize="0.10" <!-- Set Stepsize as per your need -->
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText3" />主题代码
<style name="MyRatingBar" parent="Widget.AppCompat.RatingBar">
<item name="android:progressDrawable">@drawable/custom_ratingbar</item>
</style>custom_ratingbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<bitmap
android:src="@drawable/ic_ic_star_border_blue_24dp"
android:tint="?attr/colorControlNormal" />
</item>
<item android:id="@android:id/secondaryProgress">
<bitmap
android:src="@drawable/ic_ic_star_border_blue_24dp"
android:tint="?attr/colorControlActivated" />
</item>
<item android:id="@android:id/progress">
<bitmap
android:src="@drawable/ic_ic_star_blue_24dp"
android:tint="?attr/colorControlActivated" />
</item>
输出:


已更新
这是材质图标https://material.io/icons/的源代码。
使用此源链接为可绘制的https://romannurik.github.io/应用颜色
希望它能帮上忙!
发布于 2018-01-22 20:40:19
使用以下代码:
参考资料:https://stackoverflow.com/a/37135661/8448886
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(0).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(1).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP); https://stackoverflow.com/questions/48381788
复制相似问题