Added in API level 1

RatingBar

open class RatingBar : AbsSeekBar
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.ProgressBar
   ↳ android.widget.AbsSeekBar
   ↳ android.widget.RatingBar

A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar. The smaller RatingBar style ( android.R.attr#ratingBarStyleSmall) and the larger indicator-only style (android.R.attr#ratingBarStyleIndicator) do not support user interaction and should only be used as indicators.

When using a RatingBar that supports user interaction, placing widgets to the left or right of the RatingBar is discouraged.

The number of stars set (via setNumStars(int) or in an XML layout) will be shown when the layout width is set to wrap content (if another layout width is set, the results may be unpredictable).

The secondary progress should not be modified by the client as it is used internally as the background for a fractionally filled star.

Summary

Nested classes
abstract

A callback that notifies clients when the rating has been changed.

XML attributes
android:isIndicator Whether this rating bar is an indicator (and non-changeable by the user).
android:numStars The number of stars (or rating items) to show.
android:rating The rating to set by default.
android:stepSize The step size of the rating.
Inherited XML attributes
Inherited constants
Public constructors
RatingBar(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

RatingBar(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

RatingBar(context: Context!, attrs: AttributeSet!)

RatingBar(context: Context!)

Public methods
open CharSequence!

open Int

Returns the number of stars shown.

open RatingBar.OnRatingBarChangeListener!

open Float

Gets the current rating (number of stars filled).

open Float

Gets the step size of this rating bar.

open Boolean

open Unit
setIsIndicator(isIndicator: Boolean)

Whether this rating bar should only be an indicator (thus non-changeable by the user).

open Unit
setMax(max: Int)

open Unit
setNumStars(numStars: Int)

Sets the number of stars to show.

open Unit

Sets the listener to be called when the rating changes.

open Unit
setRating(rating: Float)

Sets the rating (the number of stars filled).

open Unit
setStepSize(stepSize: Float)

Sets the step size (granularity) of this rating bar.

Protected methods
open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Inherited functions
Inherited properties

XML attributes

android:isIndicator

android:isIndicator
Whether this rating bar is an indicator (and non-changeable by the user).

May be a boolean value, such as "true" or "false".

android:numStars

android:numStars
The number of stars (or rating items) to show.

May be an integer value, such as "100".

android:rating

android:rating
The rating to set by default.

May be a floating point value, such as "1.2".

android:stepSize

android:stepSize
The step size of the rating.

May be a floating point value, such as "1.2".

Public constructors

RatingBar

Added in API level 1
RatingBar(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

RatingBar

Added in API level 1
RatingBar(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

RatingBar

Added in API level 1
RatingBar(
    context: Context!,
    attrs: AttributeSet!)

RatingBar

Added in API level 1
RatingBar(context: Context!)

Public methods

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getNumStars

Added in API level 1
open fun getNumStars(): Int

Returns the number of stars shown.

Return
Int The number of stars shown.

getOnRatingBarChangeListener

Added in API level 1
open fun getOnRatingBarChangeListener(): RatingBar.OnRatingBarChangeListener!
Return
RatingBar.OnRatingBarChangeListener! The listener (may be null) that is listening for rating change events.

getRating

Added in API level 1
open fun getRating(): Float

Gets the current rating (number of stars filled).

Return
Float The current rating.

getStepSize

Added in API level 1
open fun getStepSize(): Float

Gets the step size of this rating bar.

Return
Float The step size.

isIndicator

Added in API level 1
open fun isIndicator(): Boolean
Return
Boolean Whether this rating bar is only an indicator.

setIsIndicator

Added in API level 1
open fun setIsIndicator(isIndicator: Boolean): Unit

Whether this rating bar should only be an indicator (thus non-changeable by the user).

Parameters
isIndicator Boolean: Whether it should be an indicator.

setMax

Added in API level 1
open fun setMax(max: Int): Unit
Parameters
max Int: the upper range of this progress bar

setNumStars

Added in API level 1
open fun setNumStars(numStars: Int): Unit

Sets the number of stars to show. In order for these to be shown properly, it is recommended the layout width of this widget be wrap content.

Parameters
numStars Int: The number of stars.

setOnRatingBarChangeListener

Added in API level 1
open fun setOnRatingBarChangeListener(listener: RatingBar.OnRatingBarChangeListener!): Unit

Sets the listener to be called when the rating changes.

Parameters
listener RatingBar.OnRatingBarChangeListener!: The listener.

setRating

Added in API level 1
open fun setRating(rating: Float): Unit

Sets the rating (the number of stars filled).

Parameters
rating Float: The rating to set.

setStepSize

Added in API level 1
open fun setStepSize(stepSize: Float): Unit

Sets the step size (granularity) of this rating bar.

Parameters
stepSize Float: The step size of this rating bar. For example, if half-star granularity is wanted, this would be 0.5.

Protected methods

onMeasure

Added in API level 1
protected open fun onMeasure(
    widthMeasureSpec: Int,
    heightMeasureSpec: Int
): Unit
Parameters
widthMeasureSpec Int: horizontal space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.
heightMeasureSpec Int: vertical space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.