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