Subscripts in textview


Last Updated:

  1. gstein1231

    gstein1231 Member This Topic's Starter

    Joined:
    Dec 21, 2009
    Messages:
    12
    Likes Received:
    0
    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.
     

    Advertisement
  2. vivart

    vivart New Member

    Joined:
    Dec 15, 2009
    Messages:
    4
    Likes Received:
    0
    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 Member This Topic's Starter

    Joined:
    Dec 21, 2009
    Messages:
    12
    Likes Received:
    0
    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 New Member

    Joined:
    Dec 15, 2009
    Messages:
    4
    Likes Received:
    0
    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 Member This Topic's Starter

    Joined:
    Dec 21, 2009
    Messages:
    12
    Likes Received:
    0
    Got it. It just doesn't show up as working in the Eclipse layout preview. Thanks man!
     

Share This Page

Loading...