Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Html.fromhtml() + SpannableString

I have html string and SpannableString in this string and I put it all in the TextView, and the problem is in SpannableString, it's not shown in Html.fromhtml(). How can I show SpannableString in Html.fromHtml()? Is it possible?

    for(int index = 0; index < l.length; index++){ // have3d() return SpannableString
            x += "<font color=\"green\">" + have3d(title[index]) + " </font> <br />" + l[index] + "<br/><br/>";
            if(index == l.length-1){
                x += "<font color=\"green\">" + title[index] + " </font> <br />" + l[index] + "<br/>";
            }   
        }
mСinema.setText(Html.fromHtml(x));
like image 242
Ozik Abdullaev Avatar asked Feb 14 '13 11:02

Ozik Abdullaev


People also ask

What is the use of spannablestringbuilder in Android?

SpannableString: This is used when there is no need to modify the text but you need to modify the markup i.e. you need to add some spans to your text. SpannableStringBuilder: This is used when you need to modify the text as well as the markup. This is a quick intro about the Spans in Android. Now, let's see some of the use-cases of it.

What is the difference between spannedstring and spannablestring?

SpannedString: This is used when there is no need to modify the text or the markup after its creation. SpannableString: This is used when there is no need to modify the text but you need to modify the markup i.e. you need to add some spans to your text.

What are spans in Android text style?

The Android framework provides 20+ spans in the android.text.style package, subclassing the main interfaces and abstract classes. We can categorize spans in several ways: Based on whether span changes only appearance or also the text metric/layout Based on whether they affect text at character or at paragraph level

Is spannablestring immutable?

No modifications to the text and no modifications to the design (the spans). In other words, it’s immutable. SpannableString — This class allows for modifications of the design/styles added to the text, but no direct modification of the text used by the Spannable.


1 Answers

Html.fromHtml returns a Spanned, that you can convert to a SpannableString this way:

SpannableString text = new SpannableString(Html.fromHtml(x));

And then set it by calling:

mcinema.setText(text, BufferType.SPANNABLE);
like image 144
Michele Bontorno Avatar answered Sep 28 '22 00:09

Michele Bontorno