简体   繁体   English

如何在警报对话框的消息中换行?

[英]how to give line break in message in alert dialog box?

Using the following code I am unable to break the line to 2. 使用以下代码,我无法将行换成2。

builder.setMessage(Html.fromHtml("<b>"+"World"+"</b>+\n+second line"))

Result I get like: World+ +second line 结果我得到: World+ +second line

If you are using Html.fromHtml() then use <br/> where you want a line break for eg: 如果您使用的是Html.fromHtml()则在<br/>您要换line break使用例如:

builder.setMessage(Html.fromHtml("<b>"+"World"+"</b><br/>"+"second line"))

and if not Html and just String you can use \\n where you want a line break . 如果不是Html而是String,则可以在要换line break地方使用\\n

en..u can use '\\n',like that zh..u可以使用'\\ n',就像这样

            ProgressDialog progressDialog=new ProgressDialog(MainActivity.this);
            progressDialog.setMessage("Str1"+"\n"+"Str2"+"\n"+"Str3");
            progressDialog.show();

you can try it. 你可以试试。

您可以通过编写以下代码轻松地做到这一点:

builder.setMessage("First line \n"+"second line"));

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

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