I made ratingbar inside a viewpager. When I slided the page, it's not problem, but when I not slide it, the ratingbar isnot showing and become black and blue. then when i let the app stay on like that in a minute, the app closed itself.
this is the code:
final int y =i;
nama[y] = new TextView(context);
nama[y].setLayoutParams(lhoriparams);
nama[y].setText(arrkonten.get(i)[0]);
rating[y] = new AppCompatRatingBar(context, null, android.R.attr.ratingBarStyleIndicator);
rating[y].setLayoutParams(ratingparams);
float f = Float.parseFloat(arrkonten.get(i)[1]);
rating[y].setRating(f);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
rating[y].setBackgroundTintList(ColorStateList.valueOf(Color.TRANSPARENT));
rating[y].setSecondaryProgressTintList(ColorStateList.valueOf(Color.TRANSPARENT));
rating[y].setProgressTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.blue)));
rating[y].setElevation(10);
}
//rating[y].setStepSize(1/10);
rating[y].setNumStars(5);
rating[y].setIsIndicator(true);
linfo[i].addView(nama[y]);
linfo[i].addView(rating[y]);
please help me, Thx.
The last time I tried putting a RatingBar in my app, I had a lot of issues as well, I think it's device-related, on my device I would make it look ok, but then on some device if would appear similar to your screenshot.
I ended up creating a RatingBar on my own, it's quite easy actually, you create 2 pngs one for a selected star, and one for a not-selected star. Then create something similar in a layout xml, like this:
Where the style is:
Then you implement in your activity a method
public void onStarClicked(View v)
to catch clicks on stars on modify the background image from 0 to the clicked star.