1. Check out our companion app, Forums for Android! Download from Google Play

Subscripts in textview

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

  1. gstein1231

    gstein1231 Member
    Thread Starter
    35

    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 New Member
    5

    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 Member
    Thread Starter
    35

    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 New Member
    5

    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 Member
    Thread Starter
    35

    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...