Android textview not supporting line break

后端 未结 7 1649
遥遥无期
遥遥无期 2020-12-31 02:30

I\'m creating a custom view programmatically that is displaying text that is parsed from an XML file. The text is long and contains the \"/n\" character for force line brea

7条回答
  •  萌比男神i
    2020-12-31 03:02

    I've been having the exact same problem under the exact same circumstances. The solution is fairly straight forward.

    When you think about it, since the textview widget is displaying the text with the literal "\n" values, then the string that it is being given must be storing each "\n" like "\\n". So, when your XML string is read and stored, all occurrences of "\n" are being escaped to preserve that text as literal text.

    Anyway, all you need to do is:

    fireBody.setText(fireText.replace("\\n", "\n"));
    

    Works for me!

提交回复
热议问题