Convert Html and Set text to Textview

匿名 (未验证) 提交于 2019-12-03 03:03:02

问题:

I am trying to convert a html String and set it to a TextView but I couldn't do it exactly.

Here is my String, "Hello, %1$s! You have <b>%2$d new messages</b>"

I am using textview.setText(Html.fromHtml(myString)); which produces me an output with Html Tags instead of plain text. Can anyone help me with this?

Any help is much appreciated. Thanks

回答1:

Try use this version of setText and use SPANNABLE buffer type



回答2:

Refer to this question.

try:

textView.setText(Html.fromHtml(myString), TextView.BufferType.SPANNABLE); 


回答3:

This may be helpful to you:

Spanned marked_up = Html.fromHtml(myString); textview.setText(marked_up.toString(),BufferType.SPANNABLE); 


回答4:

A bit late but extend TextView and override SetText like so:

public override void SetText(ICharSequence text, BufferType type) {     base.SetText(Html.FromHtml(text.ToString()), BufferType.Spannable); } 

Then you can just use your TextView instead of the regular one in your axml.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!