In jetpack Compose, you can Justify a Text
like this:
Text(
text = text,
textAlign = TextAlign.Justify
)
If you want support RTL, you achive this by:
Text(
text = text,
textAlign = TextAlign.Right
)
How can a Text()
support RTL text and justify it same time in Jetpack Compose?
After several hour testing, I reach this:
@Composable
fun JustifiedRTLText(
text: String,
modifier: Modifier = Modifier
) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
Text(
text = text,
textAlign = TextAlign.Justify,
modifier = modifier,
)
}
}
In Jetpack Compose RTL or LTR will automatically set by according to the text content. But we can force it by changing the textDirection
of style
to TextDirection.Content
or TextDirection.RTL
Text(
text = text,
textAlign = TextAlign.Justify,
style = TextStyle(textDirection = TextDirection.Content)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With