setHighLightText

fun TextView.setHighLightText(search: String, @ColorInt foregroundColor: Int)(source)

Highlights occurrences of a search string within the TextView's text.

This function iterates through tokens in the search string and applies a ForegroundColorSpan and a bold StyleSpan to matching segments in the TextView's current text.

If the search string is empty, the TextView's text is reset to its original string form without any highlighting.

The matching is case-insensitive and considers locale-specific lowercase transformations. It also leverages SeslTextUtilsReflector.semGetPrefixCharForSpan to potentially adjust the search token based on prefix characters for better matching.

There's a MAX_OFFSET limit (200) to prevent excessive processing if a token appears too many times.

Parameters

search

The string to search for within the TextView's text.

foregroundColor

The color to use for highlighting the matched text. This should be a color integer (e.g., Color.RED).