简体   繁体   中英

Show a new line in a Text component in Jetpack Compose

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?

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. 截屏

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM