Measuring text width in DP
Asked Answered
C

1

2

From Is it possible to measure string width to properly size a Text composable? to find out text width, I have some questions.

I'm a little new to Jetpack Compose so can someone tell how I can call the measureTextWidth method mentioned in the above question? I basically need something like:

val textWidth = measureTextWidth(Text(text = "Hello World", style = MaterialTheme.typography.body2))

Is there any way? Or, what would be the final method definition and call to the measureTextWidth method with passing the composable as parameter instead of hardcoding in the measureTextWidth method? (I imagine Text("your sample text") is hardcoded.)

Comeon answered 5/6, 2022 at 17:44 Comment(1)
I've updated my answer with more general solution, check it out.Marcille
S
0

The measureTextWidth method mentioned in the question that you linked to does not exist. The questioner was essentially asking for an implementation of this function.

See my answer in that thread (here) for one such implementation of this function.

Silicon answered 8/12, 2023 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.