我是一个Android初学者,我想制作我的自定义ratingBar.
免责声明:这不是重复.因为我读过的所有帖子都询问如何更改星星的颜色以及如何删除笔画.那不是我想要的.我想要中风,并能够改变边框的颜色.
具有透明和黄色的笔划,同时为空,黄色背景和笔划为一半并填充.
我不想使用png.我已经拥有自己的但是它们太小了.如果我只使用XML属性和drawables制作星星,我只是不想让设计师创建新的.
<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"
/>
Run Code Online (Sandbox Code Playgroud)
我和另一位工程师一起工作.他还在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
Run Code Online (Sandbox Code Playgroud)
[所以现在它有一个灰色背景,黄色填充,现在没有中风.
我已经知道如何设置背景透明并使其变黄.我只是不知道如何设置笔触颜色.非常感谢!!!!