2

I want to display dynamically text in textview.

for example: enter image description here

Like red color mark. to see celsius temperature symbol.

java code:

TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp());

Please help me.

demo.b
  • 3,299
  • 2
  • 29
  • 29
Hemantvc
  • 2,111
  • 3
  • 30
  • 42
  • 1
    possible duplicate of [Android set degree symbol to Textview](http://stackoverflow.com/questions/3439517/android-set-degree-symbol-to-textview) – Manish Dubey Apr 03 '14 at 11:04
  • possible duplicate of [Degrees symbol (as in Degrees Celsius/Farenheight) in a TextView](http://stackoverflow.com/questions/3312001/degrees-symbol-as-in-degrees-celsius-farenheight-in-a-textview) – DroidDev Apr 03 '14 at 11:26

3 Answers3

3

You can try,

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("8<sup>o</sup>"));

where sup is known as superscript, also you can do subscript by writing

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("8<sub>o</sub>"));
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
3
TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp()  + " \u2109" + "C");
kstachniuk
  • 358
  • 1
  • 4
1

Try this to make the Celsius degree symbol red:

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("8<font color=""#f00"">°</font>"));

Note that I used the shor form for #ff0000 => #f00
You might prefer to use the named color "red", instead.

This is to make it the same color (not red):

TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp() + "°C");
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115