2013-11-26 45 views

回答

8

您可以將這些行添加到創建方法上。

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); 
1

我不認爲有辦法。每個Android版本都定義評級欄的默認樣式,默認樣式也使用圖像。所以你唯一能做的就是用你自己的圖片代替。

0
private void setRatingStarColor(Drawable drawable, @ColorInt int color) { 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      DrawableCompat.setTint(drawable, color); 
     } else { 
      drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); 
     } 
    } 
相關問題