更新Google Play服务至7.5.0后,RatingBar颜色变为白色

3
我的应用程序一直运行得很好,直到我升级到“com.google.android.gms:play-services:7.5.0”。我在一个活动中使用RatingBar,一切正常。但是升级后,评分栏的颜色变为白色。即使我尝试使用代码和布局更改颜色,颜色也会变成白色。但当我触摸评分栏时,会出现一些绿色的评分栏。 代码:
<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ratingBar"
    android:layout_gravity="center_horizontal"
    android:numStars="5"
    android:theme="@style/Theme.AppCompat.Light"
    android:stepSize="0.5"
    android:progressBackgroundTint="#ff048ec4"
    android:progressTint="#ff048ec4"
    android:progressBackgroundTintMode="multiply"
    android:progressTintMode="multiply" />

这个问题只出现在安卓5.0以下的版本中,而在安卓5.0及以上版本中并不存在此问题。具体来说,在Kitkat及更低版本中,颜色会呈现为白色。

有人知道解决方法吗?谢谢提前。

1个回答

0

对于 API >= 21

Drawable progress = ratingBar.getProgressDrawable();
DrawableCompat.setTint(progress, Color.YELLOW);

针对 API < 21

RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW,PorterDuff.Mode.SRC_ATOP);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接