Ajouter des carIcons intégrés pour les lignes

Vous pouvez ajouter des icônes intégrées au texte pour améliorer l'attrait visuel de votre application à l'aide de CarIconSpan. Pour en savoir plus sur la création de ces étendues, consultez la documentation de CarIconSpan.create pour plus d'informations. Pour obtenir une vue d'ensemble du fonctionnement du style de texte avec des étendues, consultez Appliquer des styles à du texte avec des objets Span.

val rating = SpannableString("Rating: 4.5 stars")
rating.setSpan(
    CarIconSpan.create(
        // Create a CarIcon with an image of four and a half stars
        CarIcon.Builder(
            IconCompat.createWithResource(carContext, R.drawable.ic_star)
        ).build(),
        // Align the CarIcon to the baseline of the text
        CarIconSpan.ALIGN_BASELINE
    ),
    // The start index of the span (index of the character '4')
    8,
    // The end index of the span (exclusive, length of the string)
    17,
    Spanned.SPAN_INCLUSIVE_INCLUSIVE
)

val row = Row.Builder()
    .setTitle("Rating Row")
    .addText(rating)
    .build()