Show
  • in android textview

前端 未结 7 562
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 16:15

I have String with ul and li in it. And I am trying to show them in HTML formatting in textview.
textView.setText(Html.fromHtml(myHtmlText));
But tex

7条回答
  •  悲哀的现实
    2020-12-14 16:57

    You can use Html.TagHandler.

    In your case it will be like this:

    public class UlTagHandler implements Html.TagHandler{
        @Override
        public void handleTag(boolean opening, String tag, Editable output,
                              XMLReader xmlReader) {
                if(tag.equals("ul") && !opening) output.append("\n");
                if(tag.equals("li") && opening) output.append("\n\t•");
        }
    }
    

    and

    textView.setText(Html.fromHtml(myHtmlText, null, new UlTagHandler()));
    

提交回复
热议问题