Rekar
Rekar

Reputation: 495

Format items coming from a String-Array in XML

Im trying to format items(Bold, new line, italics, etc...) In a string array in an xml file Ive created for the arrays(items.xml). Each Item is going to have a different format and Im trying to figure out a way to format each item. using \n I can get new lines, but can get bolding of text or anything else. How can this be done?

My code to display the items in the array:

Intent launchingIntent = getIntent();
String content = launchingIntent.getData().toString();
TextView viewer = (TextView) findViewById(R.id.tutView);
viewer.setText(content);   
setContentView(viewer);

It grabs the item number from a previous activity to display the text in the item in the array.

EDIT: Found the answer. Cant answer it for another 8 hours, so here it is:

I figured out, by searching the Android dev website, which I should have done first, is to use "&lt" before the bold tags, and to use Html.fromHtml(content) and it seems to do exactly what I needed.

Upvotes: 0

Views: 1015

Answers (1)

Arpit Garg
Arpit Garg

Reputation: 8546

Styling with HTML markup

You can add styling to your strings with HTML markup. For example:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="welcome">Welcome to <b>Android</b>!</string>
</resources>

Similar thing can be applied with string array in strings.xml Supported HTML elements include:

<b> for bold text.
<i> for italic text.
<u> for underline text.

Upvotes: 1

Related Questions