Skip to main content

About this widget

Displays the highlighted attributes of your search results. With InstantSearch Android, the Highlightable interface and HighlightedString objects simplify highlighting the correct words in a search response that match your query. See also: Get started with imperative UI

Explore example code

Browse the Highlighting example code on GitHub.

Examples

Consider a movies . Each movie record consists of two fields: title and year. Algolia’s response to the query “red” could look like:
JSON
To display those movies in your interface, you likely have created a data class that looks something like the following:
Kotlin
Update it to add some highlighting. Implementing 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
Use these highlighted strings in the interface, for example in a MovieViewHolder.

Using highlighted strings in an Android view

  • Directly as a SpannedString, with the highlight defaulting to bold:
    Kotlin
  • As a customized SpannedString, specifying a ParcelableSpan to use as highlight style:
    Kotlin
  • Any way you want, iterating on HighlightedString#tokens to process it however you like:
    Kotlin

Compose UI

  • Directly as a AnnotatedString, with the highlight defaulting to bold:
    Kotlin
  • As a customized AnnotatedString, specifying a SpanStyle to use as highlight style:
    Kotlin
  • Any way you want, iterating on HighlightedString#tokens to process it however you like:
    Kotlin
Last modified on July 10, 2026