android - 升级 Google Play Services 7.5.0 后 RatingBar 颜色显示为白色

标签 android android-widget google-play-services ratingbar

在我升级到“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/

相关文章:

android - 如何在我的 android 应用程序中获取 google play 商店的信息?

android - 我们能否将 Android 作为操作系统缩小到仅使用 70-80% 的实际屏幕?

android - 将 EditText 限制为带符号的十进制数

java - 找不到方法 AdvertisingIdClient.getAdvertisingIdInfo

java - SharedPreferenceclear() 抛出空指针异常

android - Android Actionbar (Marquee) 中的可自动滚动标题

android-studio - Android Studio 无法识别 InstanceID 类

java - BodyMimePart 类中的 setText() 和 setContent() 有什么区别

Android - 滑动标签 viewpager 问题

android - 包 android.support.v4.util 不存在