Reputation: 49
I am developing an Android app which parses an xml file from a online server and extracts a string from it and stores it in a local variable which is then displayed in a textview. I want some part of the extracted text to be displayed in Bold. How do I achieve that? I can make separate text view for only the Bold part and give it a bold attribute, but then I would have too many views and that would slow down the app.
I have access to the xml file on the server and I can make changes to it if required. Is there any way I could format the text in the xml file itself and then be displayed "as is" in the textview?
Upvotes: 0
Views: 97
Reputation: 1621
When you set the text in the TextView, you can load basic HTML as well, like so:
text.setText(Html.fromHtml("Hello <b>world</b>"));
In that example, "world" would be bolded.
Upvotes: 2
Reputation: 6517
Try with
textView.setText(Html.fromHtml(htmlText));
If htmlText
is let's say
example <strong>string</strong>
this will work.
Upvotes: 2