Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android use html tags in textview programmatically

I have been able to use html tags in the string ie, to set textview from resource like :

<resources>
<string name="somestring">
    <B>Title</B> <I>Italic</I><BR/>
    Content
</string>
</resources>

This works fine when the text is in resource and I set it to my textView.

Now, I want to programmatically set a string I get from server at runtime to the textView. Therefore I can't define the string in resource folder.

I tried the following

textView.setText("<B>Bold</B><I>Italic</I>");

but this doesnt work. Any help would be appreciated.

like image 994
user2041902 Avatar asked Aug 25 '26 09:08

user2041902


1 Answers

Use code like:

textview.setText(Html.fromHtml("YOUR HTML STRING"));

Hope it will help you.

like image 169
Rushabh Patel Avatar answered Aug 27 '26 00:08

Rushabh Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!