【发布时间】:2016-01-31 18:40:15
【问题描述】:
我有一个RatingBar:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.75"
android:isIndicator="false"
android:scaleY="0.75"
android:id="@+id/ratingBar"
android:stepSize="0.5"
android:numStars="5" />
我正在使用滤色器使评分栏的星星变成粉红色,如下所示:
ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Drawable progressDrawable = ratingBar.getProgressDrawable();
if (progressDrawable instanceof LayerDrawable) {
LayerDrawable stars = (LayerDrawable) progressDrawable;
stars.getDrawable(2).setColorFilter(getResources().getColor(R.color.ColorSecondary), PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(1).setColorFilter(getResources().getColor(R.color.ColorSecondary), PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(0).setColorFilter(getResources().getColor(R.color.ColorSecondary), PorterDuff.Mode.SRC_ATOP);
}
这适用于所有手机,除了 Nexus 5(Android 版本 6.0),其中 5 颗星都是粉红色的,但默认填充。即使我点击星星,它们也不会改变颜色,所有 5 颗星星都保持填充状态。
但是,当我执行ratingBar.getRating() 时,它会返回用户触摸评分栏的评分,这意味着它正在工作,只是滤色器出现故障。
如果我移除颜色过滤器,RatingBar 可以正常使用默认颜色。
似乎无法在任何地方找到解决方案。提前致谢。
【问题讨论】:
标签: android colorfilter layerdrawable