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));
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.
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.
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
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With