[英]How to change drawable of specific Star in RatingBar?
我想在足球中创建像刑罚栏这样的ratingBar
我用这种风格创建了自定义RatingBar:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/circle_grey"/>
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/circle_green"/>
<item
android:id="@android:id/progress"
android:drawable="@drawable/circle_red"/>
进一步说明:当用户有目标时,请通过ratingBar中的索引2更改可绘制的星形,如果用户操作不成功,则将ratingBar中的索引2的星形绘制可更改为红色可绘制。
怎么做?
由于要根据条件更改等级栏的颜色,因此必须通过更改图层列表以编程方式进行更改。
说出玩家是否有进球。
private static int GREEN = 0; // progress
private static int RED= 1; // secondary progress
private static int YELLOW= 2; // background
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(GREEN).setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(RED).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(YELLOW).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
如果球员没有进球,
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(GREEN).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(RED).setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(YELLOW).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
注意:确保您已在图层列表中创建了我的订单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.