在我升级到“com.google.android.gms:play-services:7.5.0”之前,我的应用程序运行良好。我在一项工作正常的 Activity 中使用 RatingBar。但是升级后,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" />
问题仅出在低于 Lollipop 的版本上。在 Lollipop 中没有问题,但在 Kitkat 及更低版本中颜色显示为白色。
有人知道解决办法吗? 提前致谢。
最佳答案
For API >= 21
Drawable progress = ratingBar.getProgressDrawable();
DrawableCompat.setTint(progress, Color.YELLOW);
For API < 21
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW,PorterDuff.Mode.SRC_ATOP);
关于android - 升级 Google Play Services 7.5.0 后 RatingBar 颜色显示为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31028434/