1. Are you ready for the Galaxy S20? Here is everything we know so far!

Subscripts in textview

Discussion in 'Android Development' started by gstein1231, Dec 21, 2009.

  1. gstein1231

    gstein1231 Newbie
    Thread Starter

    Can anyone provide some information on how to create subscripted text in a textview in my xml layout?

    For example if I wanted to display out H2O and subscript the 2.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. vivart

    vivart Lurker

    From java code you can do like this
    Code (Text):
    1.  
    2. textView = (TextView) findViewById(R.id.TextView01);
    3. textView.setText(Html.fromHtml("H<sub>2</sub>O"));
    4.  

    if you want to do this from xml resource add this line in string.xml
    Code (Text):
    1.  
    2. <string name="textViewl">H<sub>2</sub>O</string>
    3.  
    do not forget to add some bottom padding
    Code (Text):
    1.  
    2. android:paddingBottom="5dip"
    3.  
     
  3. gstein1231

    gstein1231 Newbie
    Thread Starter

    If I add that <sub> to the string resource, it doesn't get recognized. I think it only sees <b>, <i>,<u> as style commands, unless I am doing something wrong.
     
  4. vivart

    vivart Lurker

    I have tested again.Both ways are working fine at least on emulator.
    can you provide some more details like which string your are using , what output you are getting.
     
  5. gstein1231

    gstein1231 Newbie
    Thread Starter

    Got it. It just doesn't show up as working in the Eclipse layout preview. Thanks man!
     
Loading...

Share This Page

Loading...