Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting TextView text using values/strings.xml, HTML and CSS

I am trying to format a TextView with lots of text to look better, and since I feel this is very easy with HTML and CSS I thought I'd give it a go. And since having it in values/strings.xml lets you localize, I found this to be the best option. Now, I manage to get HTML in a string fine with:

<![CDATA[ <html code here> ]]>

But if I try for example:

<![CDATA[
    <html>
    <head>
    <body>
    <style type=\"text/css\">
        p {
        display: block;
        border-bottom: 1px solid #31B6E7; }
    </style>
    </head>
    ...
    etc
]]>

It will just paste the CSS code as plain text, is it not possible to format using CSS this way or does anyone have a good tip for me here?

Thanks for any help on this one.

like image 413
Fumler Avatar asked Dec 15 '22 18:12

Fumler


1 Answers

I think you're perhaps expecting a little much from the TextView, or rather, from the Html.fromHtml method, since that is what turns the HTML into a Spannable that you can use with the TextView. It's quite basic. Here's what it supports:

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

like image 67
themightyjon Avatar answered Jan 17 '23 15:01

themightyjon