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?
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)