添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接


1.相关属性:

> android:isIndicator:是否用作指示,用户无法更改,默认false
> android:numStars:显示多少个星星,必须为整数 android:rating:默认评分值,必须为浮点数
> android:stepSize: 评分每次增加的值,必须为浮点数
> android:progressBackgroundTint="@color/goCart_btn" :未选中星星的颜色
> android:progressTint="@color/goCart_btn"  :选中星星的颜色
> android:secondaryProgressTint="@color/goCart_btn"  :选中星星的边框颜色

还有两种样式供我们选择

>  style="?android:attr/ratingBarStyleIndicator"
>  style="?android:attr/ratingBarStyleSmall"

2.实现代码

  <TextView
        android:id="@+id/item_tv"
        android:text="星级评分"
        android:textSize="16sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <RatingBar
        android:rating="3.3"
        android:numStars="5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <RatingBar
        style="?android:attr/ratingBarStyleIndicator"
        android:rating="3.3"
        android:numStars="5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <RatingBar
        android:layout_marginTop="10dp"
        android:layout_marginLeft="5dp"
        style="?android:attr/ratingBarStyleSmall"
        android:rating="3.3"
        android:numStars="5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

二.如何修改选中星星的颜色

 <RatingBar
        android:rating="4.3"
        android:numStars="5"
        android:progressTint="#ffeca011"
        android:secondaryProgressTint="#ffeca011"
        android:progressBackgroundTint="#ffe7e7e7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

三.示例展示

1.xml文件

这三行是一样的,所以就给出一行代码

 <RelativeLayout
                android:id="@+id/star_describe"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/score_title1"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:text="描述相符"
                    android:textSize="13sp"
                    android:textColor="@color/theme_defaultText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:id="@+id/describe_tip"
                    android:textSize="12sp"
                    android:textColor="@color/theme_textColor"
                    android:layout_marginLeft="5dp"
                    android:layout_toRightOf="@+id/score_title1"
                    android:layout_centerVertical="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <RatingBar
                    android:id="@+id/describe_score"
                    android:layout_alignParentRight="true"
                    style="@style/Widget.AppCompat.RatingBar.Indicator"
                    android:isIndicator="false"
                    android:progressTint="@color/goCart_btn"
                    android:progressBackgroundTint="@color/eval_default_star"
                    android:secondaryProgressTint="@color/goCart_btn"
                    android:numStars="5"
                    android:stepSize="1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </RelativeLayout>
2.java代码
//监听值的变化
 private void ratingBarListener() {
        describe_score.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                String score = String.valueOf(rating);
                scoreState1 = fun_getScoreState(score);
                describe_tip.setText(scoreState1);
        });
//根据分数转换成文字展示
 private String fun_getScoreState(String score) {
        String rating = "";
        switch (score) {
            case "1.0":
                rating = "差";
                break;
            case "2.0":
                rating = "较差";
                break;
            case "3.0":
                rating = "一般";
                break;
            case "4.0":
                rating = "好";
                break;
            case "5.0":
                rating = "极好";
                break;
        return rating;
			《中华人民共和国增值电信业务经营许可证》粤B1-20160477    
			粤ICP备15070606号
				粤公网安备 44030502000120号
					
1.代金券礼包仅限2019年11月7日后注册的官网用户领取使用,同一账号仅限领取一次代金券礼包(同一实名账户、同一手机号码视为同一个用户);
2.代金券仅限云服务器订单使用,其中30元无门槛代金券使用时,订单金额需大于代金券金额;
3.本次活动代金券不与其他优惠活动叠加使用;
4.同一订单仅限使用一张代金券;
5.本次活动代金券使用期为自领取当日一个月内,到期作废,请用户尽快使用;
6.本次活动代金券仅用于用户本账户下使用,不得转让或出售;
7.本活动最终解释权归小鸟云所有;