CarIcon های درون خطی را برای ردیف ها اضافه کنید

شما می‌توانید با استفاده از CarIconSpan آیکون‌ها را به صورت درون‌خطی به متن اضافه کنید تا جذابیت بصری برنامه‌تان را افزایش دهید. برای اطلاعات بیشتر در مورد ایجاد این spanها، به مستندات CarIconSpan.create مراجعه کنید. برای مرور کلی نحوه‌ی کار استایل‌بندی متن با spanها، به Spantastic text style with Spans مراجعه کنید.

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()