Bạn có thể thêm các biểu tượng cùng dòng với văn bản để giúp ứng dụng của mình trở nên bắt mắt thông qua CarIconSpan. Hãy xem tài liệu liên quan đến CarIconSpan.create để biết thêm thông tin về cách tạo những span này. Hãy xem phần Spantastic text styling with Spans (Tạo kiểu văn bản spantastic (tuyệt vời) bằng span) để biết thông tin tổng quan về cách hoạt động của việc định kiểu văn bản bằng span.
Kotlin
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(...).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 (index of the last 's' in "stars")
16,
Spanned.SPAN_INCLUSIVE_INCLUSIVE
)
val row = Row.Builder()
...
.addText(rating)
.build()
Java
SpannableString rating = new SpannableString("Rating: 4.5 stars");
rating.setSpan(
CarIconSpan.create(
// Create a CarIcon with an image of four and a half stars
new CarIcon.Builder(...).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 (index of the last 's' in "stars")
16,
Spanned.SPAN_INCLUSIVE_INCLUSIVE
);
Row row = new Row.Builder()
...
.addText(rating)
.build();