可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.