Line Break in XML formatting?

后端 未结 5 1005
夕颜
夕颜 2021-01-31 06:56

when editing a String in XML I need to add line breaks. And I wanted to ask what is the RIGHT form when programming for android? Because
works but ECLIPS

5条回答
  •  攒了一身酷
    2021-01-31 07:27

    Here is what I use when I don't have access to the source string, e.g. for downloaded HTML:

    // replace newlines with 
    public static String replaceNewlinesWithBreaks(String source) { return source != null ? source.replaceAll("(?:\n|\r\n)","
    ") : ""; }

    For XML you should probably edit that to replace with
    instead.

    Example of its use in a function (additional calls removed for clarity):

    // remove HTML tags but preserve supported HTML text styling (if there is any)
    public static CharSequence getStyledTextFromHtml(String source) {
        return android.text.Html.fromHtml(replaceNewlinesWithBreaks(source));
    }
    

    ...and a further example:

    textView.setText(getStyledTextFromHtml(someString));
    

提交回复
热议问题