Get text from Html styled TextView

user3162875

I have a TextView which contains text with Html attributes like subscription, for example it's a chemical formula H2SO4. How can I get this text from textview, but with subscriptions (String isn't showing the subscript)

here you can see screenshot https://www.dropbox.com/s/0u9vtmqaxdnqfy5/Capture.PNG

Giru Bhai

To set H2SO4 in textview,Use subscript tag as

textview.setText(Html.fromHtml("H<sub>2</sub>SO<sub>4</sub>"), TextView.BufferType.EDITABLE);

where textview is your Textview's tag.

And get text from textview as

String str = Html.toHtml(textview.getEditableText()).toString();
anothertextview.setText(Html.fromHtml(str));

For more info see Selecting, Highlighting, or Styling Portions of Text

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related