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.

3 Answers 3

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

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

1 Comment

Thanks for more clarification and the link.
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...

1 Comment

CSS is not supported, bah, that sucks, thanks for the confirmation!
1

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

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.