您可以使用 CarIconSpan 在文字中加入圖示,提升應用程式的視覺吸引力。如要進一步瞭解如何建立這些範圍,請參閱 CarIconSpan.create 的說明文件。如要瞭解如何使用 span 設定文字樣式,請參閱「使用 Span 的 Spantastic 文字樣式」。
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()