Break sentence line with hyphen if word is too long in android jetpack compose

Viewed 843

How to break line with hyphen if word is too long to fit in.

for example:

|<----screen space----->|

"This is example of veryLongWord." // very long sentence :P

Currently sentence line break like this.

|<------screen space------>|
This is example of |<----->|empty space
veryLongWord.



I want to achieve this:

|<------screen space------>|
This is example of veryLon-
gWord.
2 Answers

So before anyone come to the rescue, as far as I looked into the Text() API, there is no solution for what you want out of the box.

Even then it does not sound like what you are looking for, the only ready to use solution I know is.

        Text(
        ...
            textAlign = TextAlign.Justify,
            softWrap = true
        ...
        )

if replace space to "\u00A0", it will work. cause your text to be treated as a single string.

Text( ... text = "your text".replace(" ", "\u00A0"), ... )

Related