Showing HTML assets in Android

I want to show a nice intro dialog when someone first visits my app (and thereafter on  request). Showing the dialog is easy, but how do I show it with HTML styling? Because that’s what I really want – paragraphs, bullet points, headings – those things are difficult to pull off in Android XML layout.

The obvious candidate is the WebView. Just get my HTML content in there and I’m golden. One problem: WebView seems mostly geared toward loading external URLs. That’s what all the tutorials show. There’s also a WebView.loadData method where you can just give it a string, but that just pushes the problem back, because you can’t really include HTML styling of any significance in an Android resource; as far as I can tell it just gets stripped out unless it’s bold, underline, or italicize.

So what about just putting my HTML in a file and loading that in? Seems like a good idea, but the only apparent way to do this is to use Resources.loadRawResource which returns an InputStream, which is pretty low-level stuff. Seriously? Has to be a better way.

And there is. I just need to put my file in the right place (the “assets” folder at the top level of my project) and refer to it with the right URL (file:///android_assets/ in the WebView.loadUrl method. Would have been nice for the official docs to mention that… I found mention of it in this forum post.

Next problem: the WebView doesn’t load the content right away – it takes a second to display in the emulator. Any way to make it preload? Not that I can see.

Tangent: I still don’t know what all the inputType settings on an EditText do. Particularly, I’m looking for the one that causes input to suggest and correct words as you’re typing. I set up a simple example project to try out all of the ones listed in the InputType class. None of them had that particular effect, so it seems I need to look further.

It seems I need to combine types. textAutoCorrect does not imply text –  have to put inputType=”text|textAutoCorrect” to get what I want. Looks like that does what I want, but not if I add “textAutoSuggest” – intuitive, no?



One Response

  1. thank you, i was looking for 2hours now for a sollution. AH!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: