views:

148

answers:

1

Hi,

I have a string array and was trying to style certain parts of the text with tags like < b>, < i>, ... but it doesn't work. The array looks like this:

<resources>
    <array name="hour1">                             
            <item>blabla\n<b>blabla</b></item>
</array>

The text is displayed in the textview like this:

tTitel.setText(Html.fromHtml(Text[ii]));

I tried it without Html.fromHtml too but this had no effect. The styling tags do work if i use them directly in the code, like:

tTitel.setText(Html.fromHtml("blabla<b>blabla</b>");

Any ideas how to style the text in an array??

Cheers, Chris

+2  A: 

You need to escape your HTML tags when they are included in an XML resource document. Instead of:

<b>

use:

&lt;b&gt;

At least, that works for ordinary string resources. I assume it works for string arrays.

CommonsWare
Thanks a lot! This works perfectly fine!Using < b> in ordinary string resources without escaping it works for me, too. That's why I hadn't thought of that.Thanks again!
ChristianS
Really? That's interesting. The last time I tried embedding un-escaped HTML in string resources, it failed. I haven't tried in over a year, though, so perhaps that was fixed and the fix didn't ripple through to string-array resources.
CommonsWare