RatingBar无需使用自定义图像即可更改星形颜色 [英] RatingBar changing star color without using custom images

查看:111
本文介绍了RatingBar无需使用自定义图像即可更改星形颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以改变星星的颜色?
我不想使用自定义图像来实现它.

Is there any way to change the color of star?
I don't want to use custom images to achieve it.

推荐答案

您可以将这些行添加到create方法上.

You can add these lines into on create method.

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

这篇关于RatingBar无需使用自定义图像即可更改星形颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆