java 换行 (\n) 在 android 中不支持?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9960491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:03:51  来源:igfitidea点击:

New line (\n) not Supporting in android?

javaandroidandroid-widgetandroid-edittextandroid-view

提问by vinothp

I am trying to split the single string in to two lines using \n in android but it shows as it is with \n too. I am expecting below,

我试图在 android 中使用 \n 将单个字符串分成两行,但它也显示为 \n 。我期待在下面,

String new = "Hi, How are you";

In EditText box I need,

在我需要的 EditText 框中,

Hi,

How are you

I know its simple question but I couldn't find a solution.

我知道它的简单问题,但我找不到解决方案。

回答by ravuya

It's "\n" - a backslash, not a forward slash.

它是 "\n" - 反斜杠,而不是正斜杠。

See this related questionfor more information about how to make a multiline text view look right.

有关如何使多行文本视图看起来正确的更多信息,请参阅此相关问题

回答by MAC

I think you are new into android development like me. It's really easy to do...

我认为您和我一样是 android 开发的新手。真的很容易做到...

You just have to do this:

你只需要这样做:

editText.setText("Hi,\nHow are you?");

回答by Ishu

In your case, replace "/n"and with "\n"and also if you need more then one EditText, then you must edit properties of EditTextas below:

在您的情况下,替换"/n"and"\n"并且如果您需要多个EditText,那么您必须编辑EditText如下属性:

android:singleLine="false" 
android:MaxLines = "5"

if you know the exact number of lines.

如果您知道确切的行数。

回答by Mayank

yes "\n"is supported in android, unfortunately "/n"is not supported yet ;)

是的"\n"android 支持,不幸的"/n"是尚不支持;)