Show a new line in a Text component in Jetpack Compose

Viewed 2620

I want to display some text using the Text composable in Jetpack Compose and the text contains a new line character '\n'. Something like below:

Text("This is the first line\nThis is the second line")

But the '\n' ends up just being text.

How can I get the Text component to display the new line on a separate line?

2 Answers

Try using Text("This is the first line\r\nThis is the second line"). This should solve your problem.

I just tried and i can see new line on preview and real device. Not sure if its about compose version or just bug. Screenshot

Related