- Welcome
- Getting started
- Foundations
-
Components
- Accordion
- Alert
- Alignment
- Aria Live
- Autosuggest
- Badge
- Banner Alert
- Bar Chart
- Blockquote
- Bottom Navigation
- Bottom Sheet
- Breadcrumb
- Breakpoint
- Button
- Calendar
- Card
- Card Button
- Carousel
- Checkbox
- Chip
- Code
- Content Cards
- Data Table
- Datepicker
- Description List
- Dialog
- Divider
- Drawer
- Field Set
- Flare
- Flat List
- Flight Leg
- Floating Action Button
- Floating Notification
- Form Label
- Form Validation
- Graphic Promotion
- Horizontal Navigation
- Icon
- Image
- Infinite Scroll
- Link
- List
- Map
- Mobile Scroll Container
- Modal
- Navigation Bar
- Nudger
- Overlay
- Page Indicator
- Pagination
- Panel
- Phone Input
- Picker
- Popover
- Price
- Progress Bar
- Radio Button
- Rating
- Scrollable Calendar
- Section List
- Select
- Skeleton
- Skip Link
- Slider
- Snackbar
- Spinner
- Split Input
- Star Rating
- Switch
- Table
- Text
- Text Input
- Theming
- Ticket
- Toast
- Tooltip
- Touchable Native Feedback
- Touchable Overlay
- Content
- Accessibility
Star Rating
Star Ratings are used for displaying a score within a given range.
Star Rating
Default
Day | Night |
---|---|
![]() |
![]() |
Interactive
Day | Night |
---|---|
![]() |
![]() |
Installation
Backpack Android is available through Maven Central. Check the main Readme for a complete installation guide.
Usage
The Star Rating component can be used in both XML and Kotlin/Java
Example of a Star Rating in XML
<net.skyscanner.backpack.starrating.BpkStarRating
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:rounding="up"
app:maxRating="5"
app:rating="2.5" />
Example of an interactive Star Rating in XML
<net.skyscanner.backpack.starrating.BpkInteractiveStarRating
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:rounding="up"
app:maxRating="5"
app:rating="2.5" />
Example of a Star Rating in Kotlin
import net.skyscanner.backpack.starrating.BpkStarRating
import net.skyscanner.backpack.starrating.RoundingType
BpkStarRating(context).apply {
maxRating = 5
rating = 2.5f
rounding = RoundingType.Up
}
Example of an interactive Star Rating in Kotlin
import net.skyscanner.backpack.starrating.BpkInteractiveStarRating
import net.skyscanner.backpack.starrating.RoundingType
BpkInteractiveStarRating(context).apply {
maxRating = 5
rating = 2.5f
rounding = RoundingType.Up
onRatingChangedListener = { current, max ->
}
}
Props
Property | Type | Default Value |
---|---|---|
maxRating | Int | 5 |
rating | Float | maxRating / 2 |
rounding | RoundingType | RoundingType.DOWN |
accessibilityStatus | String resource | - |
Theme Props
- starColor
- starFilledColor
Styles can be changed globally through bpkStarRatingStyle or bpkInterativeStarRatingStyle. Check theming for more information.
Accessibility
To ensure this component is accessible set a contentDescription for the component, unless there is a label indicating the rating available. For simpler logic you can also set accessibilityStatusRes in both XML and Kotlin/Java to announce x out of y.
The string resource needs to contain a %f and %d placeholder:
<string name="star_rating_accessibility_status">%.0f out of %d</string>
If both contentDescription and accessibilityStatusRes are set the contentDescription will be appended to the accessibility status to match status description behaviour.
Made with ❤️ by Skyscanner © 2023
© 2023 Skyscanner Backpack. Page last updated on Feb 8, 2023, 09:32