Hey there. I have a string in strings.xml that con...
# compose-android
s
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
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
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
You can probably use View interop to get the same behavior then
s
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)