The Android Transparent WebView Bug

While developing for iPad I once had a project that had to display really A LOT of formatted text, with footnotes, superscript, italic and bold so I just used a transparent UIWebView, placed my text as html-page in there and it worked brilliantly!

I expected the same thing to work for Android, but I was wrong. If you set your WebView background color to #00000000 and style your HTML-page via CSS by setting the background: transparent property, this won’t work.
At first the WebView appears transparent, but as soon as the web page has loaded, it will either have a white or black background – eventually this depends on your Android theme?
This is a known issue from Android 2.1 upwards РI stumbled upon it with Android 2.2. You can find it being tracked officially here: http://code.google.com/p/android/issues/detail?id=14749

So there I stood: what now!? I can’t be putting together a dozen TextViews and style them individually!?

Finally I did find a solution. TextViews can display formatted HTML text! Yay!

Simple code example:
TextView textBox = new TextView(context);
textBox.setText(Html.fromHtml("<big>This</big>" + "<small> actually</small>" + "<sup> works!</sup>"))

You can also just download an entire html-page from the web instead of putting together a string like in the example, it will work as well.
Just also set the property of the TextView to #00000000 and you’re good :-)

In my case, this fixed things. It gets far more complicated if you’re trying to display more than just text. For that, either match your backgrounds or wait for Googlers to find time and interest to fix this…