J'essaie de changer la couleur des étoiles en jaune.
Je ne veux pas utiliser un autre style (!), Juste changer la couleur des étoiles intégrées dans la RatingBar.Changer (seulement) la couleur de RatingBar
J'ai lu quelques tutoriels comment changer le style, ils sont tous assez similaires. Mais pour une raison quelconque, ça ne marche pas pour moi.
Quoi qu'il en soit, puisque je veux juste changer la couleur, et non tout le style, je le code ci-dessous:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
rbBookRating = (RatingBar) findViewById(R.id.rbRating);
rbBookRating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
}
});
LayerDrawable stars = (LayerDrawable) rbBookRating.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(1).setColorFilter(Color.CYAN, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(0).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
}
mise en page
<RatingBar
android:id="@+id/rbRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:isIndicator="true"
android:stepSize="0.5" />
(Il semble que) Mon application se bloque juste après this ligne:
LayerDrawable stars = (LayerDrawable) rbBookRating.getProgressDrawable();
Une suggestion?
Pouvez-vous ajouter l'erreur logcat que vous voyez? – Shmuel
veuillez ajouter logcat @Nick –