Lammert Westerhoff
08/28/2023, 3:04 PMval html = Html.fromHtml(htmlText, Html.FROM_HTML_MODE_LEGACY)
val spannedText = SpannableString(html)
val textView = TextView(requireContext())
textView.setText(spannedText, TextView.BufferType.SPANNABLE)
And this way, the TextView will display links as blue underlined text that you can click on top open the url in a browser.
I'm trying to achieve the same using Compose. I got to the following so far:
Text(buildAnnotatedString {
val html = Html.fromHtml(htmlText, Html.FROM_HTML_MODE_LEGACY)
val spannedText = SpannableString(html)
append(spannedText)
})
This however does not display any links. It just displays as plain text. Any idea how I can achieve the same behavior from the Android TextView with Compose?Kilian
08/28/2023, 3:06 PM@Composable
actual fun HtmlText(html: String, modifier: Modifier, color: Color) {
AndroidView(
modifier = modifier,
factory = { context -> TextView(context).apply { setTextColor(color.toArgb()) } },
update = { it.text = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY) }
)
}
ephemient
08/28/2023, 3:11 PMLammert Westerhoff
08/28/2023, 3:11 PMSpanStyle
. I did that with
Text(buildAnnotatedString {
withStyle(myComposeSpandStyle) {
...
}
}
I don't think I can use that directly on a TextView but I guess I can use things like the setTextColor as in your examplejefbit
08/28/2023, 3:17 PMjefbit
08/28/2023, 3:20 PMLammert Westerhoff
08/28/2023, 4:56 PM