Function

fromHtml

Converts a string with HTML tags into AnnotatedString.

AnnotatedStringFromHtml

@Composable
@Sampled
fun AnnotatedStringFromHtml() {
    // First, download a string as a plain text using one of the resources' methods. At this stage
    // you will be handling plurals and formatted strings in needed. Moreover, the string will be
    // resolved with respect to the current locale and available translations.
    val string = stringResource(id = R.string.example)

    // Next, convert a string marked with HTML tags into AnnotatedString to be displayed by Text
    val styledAnnotatedString = AnnotatedString.fromHtml(htmlString = string)

    BasicText(styledAnnotatedString)
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: