Remove extra line breaks after Html.fromHtml()

后端 未结 4 1593
花落未央
花落未央 2020-12-13 03:49

I am trying to place html into a TextView. Everything works perfectly, this is my code.

String htmlTxt = \"

Hellllo

\"; // the html is form
4条回答
  •  鱼传尺愫
    2020-12-13 04:41

    The spannable is a CharSequence, which you can manipulate.

    This works:

        myTextView.setText(noTrailingwhiteLines(html));
    
        private CharSequence noTrailingwhiteLines(CharSequence text) {
    
            while (text.charAt(text.length() - 1) == '\n') {
                text = text.subSequence(0, text.length() - 1);
            }
            return text;
        }
    

提交回复
热议问题