有什么办法可以改变星星的颜色吗?
我不想使用自定义图像来实现它。
问问题
5235 次
3 回答
8
您可以将这些行添加到 on create 方法中。
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(0).setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(1).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
于 2014-06-12T04:49:31.817 回答
1
我不认为有办法。每个 Android 版本都定义了评分栏的默认样式,并且默认样式也使用图像。所以你唯一能做的就是使用你自己的图像。
于 2013-11-26T07:31:25.960 回答
0
private void setRatingStarColor(Drawable drawable, @ColorInt int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
DrawableCompat.setTint(drawable, color);
} else {
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
于 2017-01-25T02:37:51.103 回答