Android : 移除评级栏中的边框
Android : Removing border in rating bar
我在 android 中使用默认 rating bar
并且显示了一个奇怪的灰色边框,我想删除它们。
请注意:: Whosebug 上的许多答案建议使用自己的图像,但我不想,有没有去除边框的方法?
我的代码::
<RatingBar
android:id="@+id/layout_fragment_home_recycler_view_rating_bar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:rating="4.0"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginTop="10dp"
android:layout_marginBottom="7dp"
android:layout_marginLeft="7dp" />
我得到了什么
为您的评分栏创建自定义样式
<style name="RatingBarStyle" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/ratingbar_selector</item>
<item name="android:minHeight">34dp</item>
<item name="android:maxHeight">34dp</item>
</style>
您的评分栏选择器
drawable/ratingbar_selector.xml
<item android:id="@+android:id/background"
android:drawable="@drawable/..." />
<item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/..." />
<item android:id="@+android:id/progress"
android:drawable="@drawable/..." />
试试这个,不需要图片。
public static void setRatingStyle(RatingBar ratingbar, int ratingNormalColor, int ratingProgressColor) {
LayerDrawable stars = (LayerDrawable) ratingbar.getProgressDrawable();
stars.getDrawable(0).setColorFilter(ratingNormalColor, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(2).setColorFilter(ratingProgressColor, PorterDuff.Mode.SRC_ATOP);
}
这对我有用:
RatingBar coachRating = (RatingBar) findViewById(R.id.rcoach_rbr_rating);
LayerDrawable stars = (LayerDrawable) coachRating.getProgressDrawable();
stars.getDrawable(2).setColorFilter(ContextCompat.getColor(itemView.getContext(),
R.color.colorAccent),PorterDuff.Mode.SRC_ATOP); // for filled stars
stars.getDrawable(1).setColorFilter(ContextCompat.getColor(itemView.getContext(),
R.color.white), PorterDuff.Mode.SRC_ATOP); // for half filled stars
stars.getDrawable(0).setColorFilter(ContextCompat.getColor(itemView.getContext(),
R.color.white), PorterDuff.Mode.SRC_ATOP); // for empty stars
参考:How can I set the color of android rating bar's stroke? (Not the color of the stars but the BORDER)
只需删除
style="?android:attr/ratingBarStyleSmall"
来自您的布局
我在 android 中使用默认 rating bar
并且显示了一个奇怪的灰色边框,我想删除它们。
请注意:: Whosebug 上的许多答案建议使用自己的图像,但我不想,有没有去除边框的方法?
我的代码::
<RatingBar
android:id="@+id/layout_fragment_home_recycler_view_rating_bar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:rating="4.0"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginTop="10dp"
android:layout_marginBottom="7dp"
android:layout_marginLeft="7dp" />
我得到了什么
为您的评分栏创建自定义样式
<style name="RatingBarStyle" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/ratingbar_selector</item>
<item name="android:minHeight">34dp</item>
<item name="android:maxHeight">34dp</item>
</style>
您的评分栏选择器
drawable/ratingbar_selector.xml
<item android:id="@+android:id/background"
android:drawable="@drawable/..." />
<item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/..." />
<item android:id="@+android:id/progress"
android:drawable="@drawable/..." />
试试这个,不需要图片。
public static void setRatingStyle(RatingBar ratingbar, int ratingNormalColor, int ratingProgressColor) {
LayerDrawable stars = (LayerDrawable) ratingbar.getProgressDrawable();
stars.getDrawable(0).setColorFilter(ratingNormalColor, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(2).setColorFilter(ratingProgressColor, PorterDuff.Mode.SRC_ATOP);
}
这对我有用:
RatingBar coachRating = (RatingBar) findViewById(R.id.rcoach_rbr_rating);
LayerDrawable stars = (LayerDrawable) coachRating.getProgressDrawable();
stars.getDrawable(2).setColorFilter(ContextCompat.getColor(itemView.getContext(),
R.color.colorAccent),PorterDuff.Mode.SRC_ATOP); // for filled stars
stars.getDrawable(1).setColorFilter(ContextCompat.getColor(itemView.getContext(),
R.color.white), PorterDuff.Mode.SRC_ATOP); // for half filled stars
stars.getDrawable(0).setColorFilter(ContextCompat.getColor(itemView.getContext(),
R.color.white), PorterDuff.Mode.SRC_ATOP); // for empty stars
参考:How can I set the color of android rating bar's stroke? (Not the color of the stars but the BORDER)
只需删除
style="?android:attr/ratingBarStyleSmall"
来自您的布局