How can I set the color of android rating bar's stroke? (Not the color of the stars but the BORDER)

后端 未结 5 1160
遥遥无期
遥遥无期 2020-12-14 16:24

I am an android beginner and I want to make my custom ratingBar.

Disclaimer: it\'s not a duplicate. because all the posts I have read asks about how to change colors

5条回答
  •  无人及你
    2020-12-14 16:46

    Put all drawable color to Yellow(in your case getResources().getColor(R.color.gold) for all) for set strokes and background. (for background,secondary progress and progress)

    RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
            LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
            stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
            stars.getDrawable(0).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
            stars.getDrawable(1).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP); 
    

    remove progressBackgroundTint,progressTint,secondaryProgressTint attributes from RatingBar no need of it.

    
    

    and result is ::

    Hope this will help (pink color is just background color)

    after set drawable 1 and 0 to red:

    RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
            LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
            stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
            stars.getDrawable(0).setColorFilter(Color.Red, PorterDuff.Mode.SRC_ATOP);
            stars.getDrawable(1).setColorFilter(Color.Red, PorterDuff.Mode.SRC_ATOP);
    

提交回复
热议问题