Android RatingBar: getProgressDrawable doesn't cast to right Class

后端 未结 5 1094
耶瑟儿~
耶瑟儿~ 2021-01-21 06:37

I am using

Android RatingBar change star colors

This line of code

    LayerDrawable stars = (LayerDrawable) rating_bar.getProgressDrawable();
         


        
5条回答
  •  隐瞒了意图╮
    2021-01-21 06:56

    Please try this trick, It will work fine by adding getCurrent() method to return a drawable.

    RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);

    LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable().getCurrent();

    stars.getDrawable(2).setColorFilter(getResources().getColor(R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP); stars.getDrawable(0).setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP); stars.getDrawable(1).setColorFilter(getResources().getColor(R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP);

提交回复
热议问题