Question

I have an Android app that is just a webview. The loaded page has 'fixed' and 'absolute' position divs. It works fine on Android 4+ but weird things happen on Android 2.3 and lower.

On Android 2.3 the page will load just fine but disappear when you rotate the device. On Android 2.2 the page will never be visible.

The page is loading properly but is invisible. You can click links and they will load, so the page is definitely there but it's not rendering correctly. On Android 2.3 elements of the page will flicker in and out and if you return the device to its original orientation it will be rendered properly.

I can load really simple HTML pages in the webview just fine. Only more complex pages have the problem.

I don't think I had this problem until I changed from targeting API level 12 to targeting API level 18, but I can't be sure.

Was it helpful?

Solution

This nearly killed me. I was considering just dropping support for Android 2.x! Thankfully I've found a solution. Just add the following to your CSS:

html {
    min-width:100%;
    min-height:100%;
}

The problem seems to be that, unlike on desktop browsers and Android 4+, the visible size of the HTML 'element' defaults to 0x0 instead of 100%x100%. Because my content divs have position:fixed; they don't cause the html or body elements to expand to fit them. That's my theory anyway.

Hope that helps someone!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top