4

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.

Community
  • 1
  • 1
James Oravec
  • 19,579
  • 27
  • 94
  • 160
  • AFAIK, only ``, ``, and `` are supported. – CommonsWare Apr 22 '13 at 20:23
  • @CommonsWare, so there is extra processing or filtering that is done on string resource files? – James Oravec Apr 22 '13 at 20:26
  • I'd describe it as less processing. AFAIK, string resources aren't piped through `Html.fromHtml()`, but through a simpler parser that only looks for those tags. I seem to recall trying other tags without luck, though that would have been a while ago. My assumption is that it's a matter of performance, as `Html.fromHtml()` isn't the speediest thing going. – CommonsWare Apr 22 '13 at 20:47

5 Answers5

3

You can use X\u00B2 to create X^2 in xml directly

Kolaaa
  • 248
  • 3
  • 6
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.

Omid Omidi
  • 1,670
  • 2
  • 16
  • 23
1

<string name="sup_string"> a<sup><small>n</small></sup> b </string>

an b

this worked for me.

Nannigalaxy
  • 492
  • 6
  • 17
0

You can escape like this:

<string name="acceleration"><![CDATA[%1$f m.s<sup><small>-2</small></sup>]]></string>
Thibaud Michel
  • 352
  • 3
  • 13
0

Android String Resource Superscript and Subscript for letters

You can copy and paste any of these Superscripts and Subscripts directly into your Android String Resource.

Example:

    <string name="word_with_superscript" translatable="false">Trademark ᵀᴹ</string>

Result:Trademark ᵀᴹ

Superscript and Subscript letters

Superscript capital ᴬ ᴮ ᴰ ᴱ ᴳ ᴴ ᴵ ᴶ ᴷ ᴸ ᴹ ᴺ ᴼ ᴾ ᴿ ᵀ ᵁ ⱽ ᵂ

Superscript minuscule ᵃ ᵇ ᶜ ᵈ ᵉ ᶠ ᵍ ʰ ⁱ ʲ ᵏ ˡ ᵐ ⁿ ᵒ ᵖ ʳ ˢ ᵗ ᵘ ᵛ ʷ ˣ ʸ ᶻ

Subscript minuscule ₐ ₑ ₕ ᵢ ⱼ ₖ ₗ ₘ ₙ ₒ ₚ ᵣ ₛ ₜ ᵤ ᵥ ₓ