Remove extra line breaks after Html.fromHtml()

后端 未结 4 1598
花落未央
花落未央 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:31

    You can try this:

    Spanned htmlDescription = Html.fromHtml(textWithHtml);
    String descriptionWithOutExtraSpace = new String(htmlDescription.toString()).trim();
    
    textView.setText(htmlDescription.subSequence(0, descriptionWithOutExtraSpace.length()));
    

提交回复
热议问题