Question

This is strange. I have a text in my string file which has

<sup>\u00AE</sup> 

in it. If I set this text to my TextView in xml file. It looks fine. But when I'm updating the it in the run time its not setting and displays like a normal letter.

.xml:

android:text="@string/you_dont_have_a_card"
android:id="@+id/txtNoCard"

.java

txtNoCard.setText(Html.fromHtml(getString(R.string.your_card_is_not_activated)));

strings.xml:

<string name="you_dont_have_a_card">It appears you do not have a TestVisa<sup>\u00AE</sup> Debit Card on file.</string>
Was it helpful?

Solution

In XML, < and > are special characters. When including them, to avoid having the parser read them as enclosing tags, they have to be described as Entities.

In this case :

&lt;sup&gt;\u00AE&lt;/sup&gt;

The surprising thing in this case is the behavior of the TextView when the text is added directly as android:text="@string/you_dont_have_a_card", which apparently uses a parser with a different behavior when facing special characters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top