问题
I need to use a break-line in a AlertDialog
on Android.
I already tried with the "\n" character but it doesn't work. I don't see the "\n" character but the text wont wrap.
Any help?
回答1:
You can use Spanned text using Html.fromHtml("some string" + "<br>")
to create new line on some textview element.
回答2:
If you are receiving the String from somewhere, maybe the \n
is being escaped.
Try with:
string = string.replace("\\n","\n");
回答3:
How about using the HTML tag to set new text?
controlName.setText(Html.fromHtml(outputString + "<br/>" + outputString2));
回答4:
It doesn't matter when use "\n" in Dialog or Activity/Fragment.
I faced the same issue but it turned out the TextView have the attribute: android:singleLine="true" or android:maxLines="1", it conflicts with "\n" so make sure to REMOVE these attributes first.
来源:https://stackoverflow.com/questions/24166315/alertdialog-message-with-new-line-n-doesnt-work