Multiline TextView in Android?

前端 未结 20 1817
南方客
南方客 2020-11-29 17:26

I did like below in xml


    

        
20条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 18:18

    First replace "\n" with its Html equavalent "<br>" then call Html.fromHtml() on the string. Follow below steps:

    String text= model.getMessageBody().toString().replace("\n", "<br>")
    textView.setText(Html.fromHtml(Html.fromHtml(text).toString()))
    

    This works perfectly.

提交回复
热议问题