Original link: magdamiu.com/2019/03/01/…

By MAGDA MIU

The Rating Bar is an extension of the Seek Bar and ProgressBar, showing the stars, according to the official documentation.

Code:

<RatingBar android:id="@+id/rating_bar_basic" android:layout_width="wrap_content" android:layout_height="wrap_content" Android: numStars = "5" android: rating = "3.5" android: stepSize = "0.5" / >Copy the code

Results:

Read only rating column

It is only used to display the current rating. If the “is Index ator” is false, it will allow the user to edit the rating.

Code:

<RatingBar android:id="@+id/rating_bar_small" style="@style/Widget.AppCompat.RatingBar.Small" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/space_16" Android :isIndicator="false" Android :numStars="5" Android :rating=" 56 "Android :stepSize=" 50" />Copy the code

Results:

Small rating

By default, it behaves just like indicator one, but if “indicator” is false, it will allow the user to edit the rating.

Code:

<RatingBar android:id="@+id/rating_bar_small" style="@style/Widget.AppCompat.RatingBar.Small" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/space_16" Android :isIndicator="false" Android :numStars="5" Android :rating=" 56 "Android :stepSize=" 50" />Copy the code

Results (third) :

RatingBar changes the listener

Code:

RatingBar ratingBar = findViewById(R.id.rating_bar_basic); ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float v, boolean b) { Toast.makeText(RatingBarActivity.this, getString(R.string.current_rating) + ratingBar.getRating(), Toast.LENGTH_SHORT).show(); }});Copy the code

Results: