Hi guys, I want to use `letterSpacing` in my `Text...
# compose
k
Hi guys, I want to use
letterSpacing
in my
Text()
. I did it like this
Copy code
letterSpacing = 0.7.sp
but when I move this value to
dimen.xml
and using like this
Copy code
letterSpacing = dimensionResource(id = R.dimen.text_letter_spacing),
It giving me error on
Text()
. Error in thread
Copy code
None of the following functions can be called with the arguments supplied.
Text(AnnotatedString, Modifier = ..., Color = ..., TextUnit = ..., FontStyle? = ..., FontWeight? = ..., FontFamily? = ..., TextUnit = ..., TextDecoration? = ..., TextAlign? = ..., TextUnit = ..., TextOverflow = ..., Boolean = ..., Int = ..., Map<String, InlineTextContent> = ..., (TextLayoutResult) → Unit = ..., TextStyle = ...) defined in androidx.compose.material
Text(String, Modifier = ..., Color = ..., TextUnit = ..., FontStyle? = ..., FontWeight? = ..., FontFamily? = ..., TextUnit = ..., TextDecoration? = ..., TextAlign? = ..., TextUnit = ..., TextOverflow = ..., Boolean = ..., Int = ..., (TextLayoutResult) → Unit = ..., TextStyle = ...) defined in androidx.compose.material
r
dimensionResource
returns a value in
dp
but
letterSpacing
expects
TextUnit
k
So, is there no way to convert those values?
c
you can use the
LocalDensity
for convertion:
Copy code
letterSpacing = with(LocalDensity.current){dimensionResource(id=R.dimen.text_letter_spacing).toSp()}
k
It works. Thanks 🙏
c
Not sure though if it is the correct value. so
dimensionResource
will return a
dp
and with this method you are then converting this
dp
into
sp
r
No it’s fine
sp are dp multiplied by the user selected font scale factor
k
perfect 😊
c
Just beware that letterSpacing doesn't play nice with elipssis text. Longstanding android text bug, we removed letterSpacing because we use maxLines 1 or 2 in a bunch of places with elipssis and the letterspacing ruins our design because of the android bug
s
Got any repro of this Colton? We're using the same and I haven't noticed it before
s
I believe i fixed a letterspacing, ellipsis and one more thing not playing well each other in compose.
c
@Stylianos Gakis yeah I think the repro was pretty simple. I think i filed like 2+ bugs about it that @Siyamed said will have to be fixed in Android 13 or 14 since it was an OS level issue with Text. let me look up the issue tracker.
d
If you have a visual of the issue you can share it would be great too, sounds like I'll hit this issue soon too so I'd rather get ahead of it 😄