comment changer la couleur de la barre d'evaluation en fonction du nombre d'étoiles?
Comment faire la suite?
si la barre d'evaluation a 1-3 étoiles - étoiles rouges.
si la barre d'evaluation 4 étoiles - étoiles jaunes.
si la barre d'evaluation a 5 étoiles - étoiles vertes.
((RatingBar) layout.findViewById(R.id.ratingBar)).setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate()));
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar" android:stepSize="1" android:clickable="false"
style="?android:attr/ratingBarStyleSmall" android:layout_gravity="right"
android:layout_marginRight="15dp" />
EDIT:
@Override
public View getItemView(int section, int position, View convertView, ViewGroup parent) {
LinearLayout layout;
if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = (LinearLayout) inflator.inflate(R.layout.item_survey, null);
} else {
layout = (LinearLayout) convertView;
}
((TextView) layout.findViewById(R.id.questionSurvey)).setText(surveyBeans.get(section).get(position).getQuestion());
RatingBar ratingBar = ((RatingBar) layout.findViewById(R.id.ratingBar));
ratingBar.setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate()));
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(1).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
((TextView) layout.findViewById(R.id.commentSurvey)).setText(surveyBeans.get(section).get(position).getComment());
return layout;
}
code de travail après avoir répondu @Murtaza Hussain:
RatingBar ratingBar = ((RatingBar) layout.findViewById(R.id.ratingBar));
ratingBar.setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate()));
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
if (ratingBar.getRating()<=3) {
stars.getDrawable(2).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
}
if(ratingBar.getRating()==4){
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
}
if(ratingBar.getRating()==5){
stars.getDrawable(2).setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
}
Jetez un oeil à ce post: stackoverflow.com/questions/2446270/...
OriginalL'auteur Valera Valerianov | 2014-12-16
Vous devez vous connecter pour publier un commentaire.
OU
Vous pouvez le faire sur
À partir de votre code
na pas obtenir de vous. que voulez-vous ?
si 1, 2 ou 3 étoiles - elles sont de couleur rouge, et le reste - de-gris. si 4 étoiles - 4 étoiles est jaune et un gris.si les 5 étoiles - 5 - vert
étoile vide toujours gris! plein d'étoiles - changement de couleur en fonction du nombre de
setOnRatingBarChangeListener se déclenche lorsque vous modifiez la cote. la cote" valeurs indique des valeurs au total, de sorte que vous pouvez changer la couleur dans le setOnRatingBarChangeListener "
OriginalL'auteur Murtaza Khursheed Hussain
garder ces deux lignes dans la barre d'evaluation, active étoiles couleur or. de travail pour lollipop
OriginalL'auteur Hari Krishna Salver