https://kotlinlang.org logo
#compose
Title
# compose
a

Arpit Shukla

01/21/2022, 6:27 PM
I have a string resource that has some html tags in it. Ex.
"This is a <b>bold</b> text."
In View world I was able to directly use this resource and put it in a TextView as it accepts a
CharSequence
for text. In Compose, however, I need to create an
AnnotatedString
out of this resource to display it in a Text composable. How to do this?
r

rsktash

01/21/2022, 7:24 PM
You can write parser
c

Casey Brooks

01/21/2022, 7:47 PM
I've written a library for displaying these kinds of formatted strings that you may find helpful https://github.com/copper-leaf/thistle
👍 1
d

David W

01/21/2022, 7:58 PM
I used this SO answer, which has a file you can simply drop into your project: https://stackoverflow.com/a/68241339/1622788
👍 1
you would write
Text("This is a <b>bold</b> text.".parseHtml())
c

Colton Idle

01/22/2022, 7:31 AM
I think Zach K worked on some sort of html parser or something that he handed off to some other community member here. I know that's not necessarily helpful, but I could've sworn that he worked on something like that before joining the Compose team. lol
17 Views