https://kotlinlang.org logo
#compose-android
Title
# compose-android
s

s3rius

02/26/2024, 4:05 PM
Hey there. I have a string in strings.xml that contains a link such as this:
<string name="my_link">This is a <a href='<https://www.hello.world>'>Hello World</a></string>
How can I render this as a clickable span in a Compose
Text
? I assume I have to turn it into an AnnotatedString, but I can't find much about how to turn an Android Text into an AnnotatedString. Is there an existing mechanism?
s

Stylianos Gakis

02/26/2024, 4:09 PM
Not sure if this is exactly what you are looking for, but we do have markdown in some places rendered by this https://github.com/halilozercan/compose-richtext
s

s3rius

02/27/2024, 7:56 AM
Not really; we keep all our strings in strings.xml for translation. And I'm looking for a way to conveniently load strings that contain these hrefs. It works pretty well for TextView.
s

Stylianos Gakis

02/27/2024, 8:02 AM
You can probably use View interop to get the same behavior then
s

s3rius

02/27/2024, 8:49 AM
For the record: Stackoverflow has an answer that also works https://stackoverflow.com/a/70162451 It translates a SpannedText into an AnnotatedString. It's trivial to add URLAnnotation as another case (which is missing in the SO answer)