简体   繁体   English

在 Jetpack Compose 的文本组件中显示新行

[英]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 '.我想使用 Jetpack Compose 中的可组合文本显示一些文本,并且文本包含换行符“ \n ”。 Something like below:如下所示:

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

But the ' \n ' ends up just being text.但 ' \n ' 最终只是文本。

How can I get the Text component to display the new line on a separate line?如何让 Text 组件在单独的行上显示新行?

Try using Text("This is the first line\r\nThis is the second line") .尝试使用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.不确定它是关于撰写版本还是只是错误。 截屏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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