DialogFragment setMessage using newLine

I am trying to set some text in DialogFragment and this text contains some new lines.

I tried all this:

setMessage("This is line A \n This is line b");

setMessage("This is line A \\\n This is line b");

setMessage("This is line A+"System.getProperty("line.separator")"+This is line b");

Does not work.

What advice?

+4
source share
2 answers

You must set your string as a resource in the strings.xml file and then get it using the getString method.

Take a look here for more details: String Newline resource / n not possible?

0
source

I would recommend using a custom layout for your dialog, or you could just use

 String message = "First sentence \r\n Second sentence \r\n ..." 
0
source

Source: https://habr.com/ru/post/1501688/


All Articles