Convert Html and set text to text box

I am trying to convert an html String and set it to a TextView, but I could not do it for sure.

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

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

Any help is greatly appreciated. Thanks

+4
source share
5 answers

Try using this version of setText and use the buffer type SPANNABLE

+2
source

Refer to this question .

to try:

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

This may be useful for you:

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

A bit late, but expanding the TextView and overriding SetText as follows:

 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 usual one in your axml.

0
source

even later ... Html.fromHtml is deprecated now:

 textView.setText( Html.fromHtml(model.getValue(), Html.FROM_HTML_MODE_COMPACT), TextView.BufferType.SPANNABLE); 

Html.FROM_HTML_MODE_COMPACT worked well for me, explore other flags for different HTML parsing behavior.

0
source

Source: https://habr.com/ru/post/1381629/


All Articles