0

I'm trying to superscript a number in a title in androidplot, like so:

strings file:

<string name="plot_title_3m">stuff per m<sup>3</sup></string>

xml file:

androidPlot.title="@string/plot_title_3m"

but it doesn't superscript at all, the number is normal styling. I've also tried using

<string name="plot_title_3m">stuff per m&lt;sup&gt;3&lt;/sup&gt;</string>

but no dice, it actually shows the sup tags in the title

also tried this

<string name="plot_title_3m">stuff per m<small><sup>3</sup></small></string>

and actually found out that the 'small' tags don't work either...

Jon
  • 9,156
  • 9
  • 56
  • 73
wordsforthewise
  • 13,746
  • 5
  • 87
  • 117
  • Looking at the source code for [androidPlot](https://bitbucket.org/androidplot/androidplot/src/397fac6a3541b4020a716e958a9c0b42bd2450fd/AndroidPlot-Core/src/main/java/com/androidplot/Plot.java?at=master#cl-831), I do not think this is possible without some modification of the source. To show superscript on a TextView, you need to pass in a `Spannable` to `TextView#setText(CharSequence)`, but androidPlot currently converts title text to a plain String. – ugo May 18 '15 at 05:32
  • Thanks, that's what I was afraid of. – wordsforthewise May 19 '15 at 04:40

1 Answers1

0

You can use HTML tags to achieve this. To be more exact, you need to use Spans on your input text to achieve this look on TextView, but we have a friendly neighborhood helper class that converts some common HTML tags into spans.

E.g.:

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("X<sup>2</sup>"));
Community
  • 1
  • 1
Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101
  • I don't think that would work since the whole plot has an ID, but not the title... – wordsforthewise May 19 '15 at 04:40
  • Oh, you're right, I misinterpreted the problem. I agree with Ugo, you could try to modify the lib accordingly and somehow pass in a Spannable. OR maybe you could extract the title from the plotting View and show it in a separate TextView? – Zsombor Erdődy-Nagy May 19 '15 at 05:15