4

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.

Fumler
  • 465
  • 6
  • 15

3 Answers3

6

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

themightyjon
  • 1,241
  • 11
  • 12
5

You have to tell the TextView that it is receiving HTML. I think you can find you answer here. That goes for HTML. CSS is not supported - you have to do it via your layout XML...

Community
  • 1
  • 1
Chris
  • 4,403
  • 4
  • 42
  • 54
1

You could use android.webkit.WebView.loadData() to render the HTML + CSS, instead of a TextView.

Trebor Rude
  • 1,904
  • 1
  • 21
  • 31