About this widget
Displays the highlighted attributes of your search results. With InstantSearch Android, theHighlightable interface and HighlightedString objects simplify highlighting the correct words in a search response that match your query.
See also: Get started with imperative UI
Examples
Consider a movies index. Each movie record consists of two fields:title and year.
Algolia’s response to the query “red” could look like:
JSON
data class that looks something like the following:
Kotlin
Highlightable will deserialize the _highlightResult for each movie, and make it available through the getHighlight{s} methods. Create @Transient attributes for each highlight to display, being either single values or lists:
Kotlin
MovieViewHolder.
Using highlighted strings in an Android view
-
Directly as a
SpannedString, with the highlight defaulting to bold:Kotlin -
As a customized
SpannedString, specifying aParcelableSpanto use as highlight style:Kotlin -
Any way you want, iterating on
HighlightedString#tokensto process it however you like:Kotlin
Compose UI
-
Directly as a
AnnotatedString, with the highlight defaulting to bold:Kotlin -
As a customized
AnnotatedString, specifying aSpanStyleto use as highlight style:Kotlin -
Any way you want, iterating on
HighlightedString#tokensto process it however you like:Kotlin