-->

Android String Resource Superscript

2019-01-15 17:32发布

问题:

I have a string resource file, which I want to pull strings from and I want one of the strings to have some superscript in it.

From http://developer.android.com/guide/topics/resources/string-resource.html it looks like the supported tags include <b>, <i>, and <u>. I'm curious if it should work for other related tags, such as <sup>... if so then my problem is solved.

Testing the above should be easy enough, I'm just looking for a deeper understanding, to see if everything is processed similar to Subscript and Superscript a String in Android or if there is extra processing that happens when pulling the strings from the resource string file.

回答1:

I am using this trick: In string resource:

<string name="text1">x!sup@2!/sup@</string>

Then in activity:

text1.setText(Html.fromHtml(getString(R.string.text1).replace("!", "<").replace("@", ">")));

this trick is working.



回答2:

You can escape like this:

<string name="acceleration"><![CDATA[%1$f m.s<sup><small>-2</small></sup>]]></string>