在 Android webview 中,我加载了一个简单的 html 页面,其中的 div 设置为 100% 宽度和高度。我在浏览器中工作正常但是在 Galaxy Nexus 4.4.2 上我看不到内容 div。 调试 div,内容似乎没有宽度。
以下是 WebView 设置:
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);
这是示例 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>
这是CSS:
body {
background-color: blue;
}
.component {
width: 100%;
height: 100%;
background-color: green;
overflow: hidden;
}
有了这个,我希望看到一个带有文本字段的绿色框。 相反,我只看到 body 的蓝色背景。 如果我删除溢出,我可以看到文本字段,但它是不可选择的 如果将 100% 替换为固定值,我将看到一个绿色框,但同样无法选择文本字段。
大概组件 div 没有显示,因为当使用 100% 时它的 w/h 是 0。 有人知道为什么吗? 以及为什么我无法输入任何文本。
谢谢
最佳答案
所以问题是我们过度编写了 onSizeChanged 方法并且没有调用 super。 调用 Super.onSizeChanged(w,h,oldw,oldh) 解决了这个问题。 感谢所有的输入
关于Android webview 4.4 css 100% 不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22257116/