Android RatingBar: getProgressDrawable doesn't cast to right Class

后端 未结 5 1097
耶瑟儿~
耶瑟儿~ 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:48

    Creating a subclass of RatingDialog and using that instead ofandroid.widget.RatingBar worked for me. Here is the code I used.

    Subclass:

    public class RatingBar extends android.widget.RatingBar {
    public RatingBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    
    public RatingBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    }
    

    Then in my layouts:

     
    

    Then in the classes where you are casting the class, just use your.package.RatingBar instead of android.widget.RatingBar

提交回复
热议问题