1. Download our Official Android App: Forums for Android!

Apps Subscripts in textview

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

  1. gstein1231

    gstein1231 Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    12
    Joined:
    Dec 21, 2009

    Dec 21, 2009
    12
    0
    35
    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 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Dec 15, 2009

    Dec 15, 2009
    4
    0
    5
    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
    Rank:
    None
    Points:
    35
    Posts:
    12
    Joined:
    Dec 21, 2009

    Dec 21, 2009
    12
    0
    35
    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
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Dec 15, 2009

    Dec 15, 2009
    4
    0
    5
    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
    Rank:
    None
    Points:
    35
    Posts:
    12
    Joined:
    Dec 21, 2009

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

Share This Page

Loading...