简体   繁体   中英

Android webview 4.4 css 100% does not show anything

In a Android webview I load up a simple html page which has a div set to 100% width and height. I works fine in the browser however on a Galaxy Nexus 4.4.2 I can not see the content div. Debugging the div it seems like the content has no width.

Here are the webview settings:

    setScrollContainer(false);
    setBackgroundColor(Color.RED);
    setHorizontalScrollBarEnabled(false);
    setHorizontalScrollbarOverlay(false);
    setVerticalScrollBarEnabled(false);
    setVerticalScrollbarOverlay(false);
    this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    WebSettings ws = getSettings();
    ws.setSupportZoom(false);
    ws.setJavaScriptEnabled(true);
    ws.setUseWideViewPort(true);
    ws.setLoadWithOverviewMode(true);
    ws.setCacheMode(WebSettings.LOAD_NO_CACHE);
    ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    ws.setAllowFileAccess(true);
    ws.setAllowFileAccessFromFileURLs(true);

Here is the sample html:

<html>
 <head>
    <title>Title</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="cache-control" content="no-cache" />
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta id="myvp" name="viewport" content="width=400, height=300, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="./main.css">
    </head>
    <body>
    <div class="component">
            <input type="text">
    </div>
    </body>
</html>

And here is the css:

body {
    background-color: blue;
}

.component {
    width: 100%;
    height: 100%;
    background-color: green;
    overflow: hidden;
}

With this I expect to see a green box with a text field in it. Instead I just see the blue background of the body. If I remove overflow I can see the text field but it is not selectable And if is replace 100% with fix values I will see a green box but again the text field is not selectable.

Presumably the component div is not showing up because when using 100% its w/h is 0. Does anyone know why this is? And also why I am unable to enter any text.

Thanks

So the problem was we were over writing the the onSizeChanged method and did not call super. Calling Super.onSizeChanged(w,h,oldw,oldh) fixed the issue. Thanks for all the input

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM