https://kotlinlang.org logo
Title
l

Lucien Guimaraes

12/14/2021, 6:52 PM
About AnnotatedString API to have multiple styles for a text, how to achieve it with a string resource? Let's say I have the following one:
<string name="news_count_title">{{count}} {{text}}</string>
. I would like
count
and
text
to have different styles. How to properly achieve it in Compose?
s

Siyamed

12/14/2021, 6:59 PM
Not implemented in compose yet. :/ there is a ticket with title (~)Styled string resource
I didn't think much yet, but if i were to do it today i'd use Annotation class/tag in string resources and create an AnnotatedString from the Spanned i have.
l

Lucien Guimaraes

12/14/2021, 7:04 PM
Not implemented in compose yet. 😕 there is a ticket with title (~)Styled string resource
this one: https://issuetracker.google.com/issues/139320238 ?
s

Siyamed

12/14/2021, 7:06 PM
Yes
Please feel free to star/vote it since we use votes in our prioritization
👍 1
l

Lucien Guimaraes

12/14/2021, 7:07 PM
I didn't think much yet, but if i were to do it today i'd use Annotation class/tag in string resources and create an AnnotatedString from the Spanned i have.
That's the solution I had in mind too 👍 I'm already using it to have clickable text inside a string. I was just hoping for something out of the box
c

Casey Brooks

12/14/2021, 10:43 PM
I just released a library on top of the Compose AnnotatedString API to make this much easier https://github.com/copper-leaf/thistle
j

Johan Reitan

12/15/2021, 8:55 AM
I'm quite happy with my solution: https://stackoverflow.com/a/69045782/1490484