【发布时间】:2016-05-24 12:25:08
【问题描述】:
我是一名 android 初学者,我想制作我的自定义 ratingBar。
免责声明:它不是重复的。因为我读过的所有帖子都询问如何更改星星的颜色以及如何删除笔触。那不是我想要的。我想要描边并且能够改变边框的颜色。
空白时使用透明和黄色的笔触,黄色背景和笔触表示一半和填充。
我不想使用 png。我已经有自己的了,但它们太小了。我只是不想让设计师制作新的,我是否可以只使用 XML 属性和可绘制对象来制作星星。
<RatingBar
android:id="@+id/thread_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:numStars="5"
android:progressBackgroundTint="@color/gray"
android:progressTint="@color/gold"
android:rating="2.5"
android:secondaryProgressTint="@color/gray"
android:stepSize="0.5"
style="?android:attr/ratingBarStyleSmall"
/>
我与另一位工程师一起工作。他还在java文件中写了代码
private void setRatingBarStart(RatingBar rating_bar) {
LayerDrawable stars = (LayerDrawable) rating_bar.getProgressDrawable();
stars.getDrawable(2)
.setColorFilter(getResources().getColor(R.color.gold),
PorterDuff.Mode.SRC_ATOP); // for filled stars
stars.getDrawable(1)
.setColorFilter(getResources().getColor(R.color.light_gray),
PorterDuff.Mode.SRC_ATOP); // for half filled stars
stars.getDrawable(0)
.setColorFilter(getResources().getColor(R.color.light_gray),
PorterDuff.Mode.SRC_ATOP); // for empty stars
[所以现在它有灰色背景,黄色表示填充,现在没有笔划。
我已经知道如何将背景设置为透明并使其变黄。我只是不知道如何设置笔触颜色。非常感谢!!!!
【问题讨论】:
-
看看这个线程..stackoverflow.com/questions/5800657/… 只需为 stras(空、填充和半填充)设置三个不同的 png,其中包含笔画和内部颜色,工作就完成了
-
@AlessioTrecani 您好,感谢您的评论。我不想要png。我已经有了,但它们太小了。如果我可以使用 XML 属性设置星星,我尽量不要求设计师制作新的
-
@huskylove 检查我的答案。
-
我不明白 PNG 的问题,你可以设置你想要的大小,如果你想要自定义评分栏,我认为这是唯一的解决方案。
标签: java android xml drawable ratingbar