androidcssfromhtml

use of HtmlSpanner with an css file added to it


HtmlSpanner with css

I have found an library called HtmlSpanner that should help me with adding a html string with css to a TextView.

but i cant find any documentation on it except

(new HtmlSpanner()).fromHtml()

but nothing on how to include a css file to it or how i can create an TagManager on handeling the css

can anyone help me?


Solution

  • Out of the box HtmlSpanner does parse blocks, and is able to apply the CSS styles in those blocks to the text. The code for that is in the StyleNodeHandler handler class.

    Now the good news is that it's pretty easy to add new TagNodeHandler classes, and in your case all you'd need is to add one that does the following:

    1. List item
    2. Read the "href" property from the CSS link
    3. Retrieve the URL that the href points to and read it into a String
    4. Parse the String into a CSS rule
    5. Register that CSS rule

    Steps 3 and 4 are already in the StyleNodeHandler class (in the parseCSSFromText method), so you'd only need to implement steps 1 and 2.

    Here's a quick Gist of what you'd need to add:

    link