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.
     


  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...
Similar Threads - Subscripts textview
  1. idiaagba
    Replies:
    6
    Views:
    297
  2. Peter22
    Replies:
    2
    Views:
    576
  3. Android News
    Replies:
    0
    Views:
    63
  4. amar94
    Replies:
    0
    Views:
    219
  5. DeveloperLIS
    Replies:
    4
    Views:
    211
  6. slightedge411
    Replies:
    2
    Views:
    383
  7. Dibakar Mistry
    Replies:
    1
    Views:
    1,368
  8. Veclar
    Replies:
    1
    Views:
    626
  9. DandSquare
    Replies:
    0
    Views:
    574
  10. dancamdev
    Replies:
    12
    Views:
    829

Share This Page

Loading...