androidandroid-jetpack-composeandroid-jetpack-compose-text

Jetpack compose display html in text


I have a string that contains html, how can I display this in a Jetpack compose Text?

In a TextView I would use a Spanned and do something like:

TextView.setText(Html.fromHtml("<p>something", HtmlCompat.FROM_HTML_MODE_LEGACY)

How can I do this with Text from Jetpack compose?


Solution

  • There is now an official way since version 1.7.0 of library androidx.compose.ui:ui

    Here is a simple example:

    Text(AnnotatedString.fromHtml("<b>Bold</b> text"))