“主体背景颜色:透明”对android 4.0.3的webview没有影响
我想在 imageView 上的静态图像上显示 webView。
我为 webView 设置了透明颜色,就像这样
webview.setBackground(0);
我将背景颜色设置为透明
<html>
<head>
</head>
<body style="background-color:transparent">
</body>
</html>
,但 Webview 的背景保持显示为白色。
我提出了任何问题并尝试了下一页的解决方案,但没有什么可以改变的。
你有什么想法吗?请帮我。
I want to display webView on static image on imageView.
I set transparent color to webView like this
webview.setBackground(0);
I set background-color as transparent
<html>
<head>
</head>
<body style="background-color:transparent">
</body>
</html>
but Webview's background keep displaying as white.
I show any questions and try these following page's solution but nothing to change.
- Android WebView style background-color:transparent ignored on android 2.2
- Transparent Background + Flash in WebView on Android 3.0+?
Do you have any ideas? Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在带有 ICS (4.0) 的设备上遇到了与白色 WebView 背景相同的问题!
NcJlee 的答案确实从 web 视图中删除了白色背景,但它需要 API 级别 11!它不适用于较旧的 API!
解决方案是在 .xml 布局资源中的 webview 上设置 android:layerType="software" 属性。
I ran into the same problem with the white WebView background on a device with ICS (4.0)!
The answer from NcJlee did remove the white background from the webview, but it requires API level 11! It will not work on older API's!
The solution is to set a android:layerType="software" attribute on the webview in the .xml layout resource.
避免这种情况的一种方法是取消选中“强制 GPU 渲染”,
但这并不能解决问题。我已经在模拟器中尝试过这段代码并且它有效。通过使用软件而不是硬件加速来强制 webview 渲染。
它能解决您的问题吗?
One way to avoid this is to uncheck "Force GPU Rendering" in
But that doesn't solve the problem. I've tried this code in emulator and it works. By forcing the webview to render by using software instead of hardware acceleration.
Does it solve your problem?
尝试使用此代码来传输 webview
try this code to transprent webview
尝试调用 setLayerType 或在 xml 中指定 android:layerType 会导致编译错误。尽管将 minSdkVersion 或 targetSdkVersion 设置为 11+,还是发生了这种情况。
因此,我最终按照以下建议使用反射来调用 setLayerType: Transparent WebView不适用于 Android v4.0
attempts to invoke setLayerType or specify android:layerType in xml caused compilation errors for me. This happened despite setting minSdkVersion or targetSdkVersion to 11+.
So, I ended up using reflection to call setLayerType as recommended in: Transparent WebView not working on Android v4.0