0

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?

2 Answers 2

2

Try with

textView.setText(Html.fromHtml(htmlText));

If htmlText is let's say

example <strong>string</strong>

this will work.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Sorry if this sounds noobish, But I have a string from a xml file, the string doesnt have any tags in it.
Let's say your xml contains the phrase "hello world". You could add the <strong> tag around "world" programmatically before calling Html.fromHtml().
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.