“主体背景颜色:透明”对android 4.0.3的webview没有影响

发布于 2024-12-27 05:51:10 字数 738 浏览 2 评论 0原文

我想在 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.

Do you have any ideas? Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

垂暮老矣 2025-01-03 05:51:10

我在带有 ICS (4.0) 的设备上遇到了与白色 WebView 背景相同的问题!

NcJlee 的答案确实从 web 视图中删除了白色背景,但它需要 API 级别 11!它不适用于较旧的 API!

    webView.setBackgroundColor(0);
    webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

解决方案是在 .xml 布局资源中的 webview 上设置 android:layerType="software" 属性。

    <WebView
        android:id="@+id/webviev"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        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!

    webView.setBackgroundColor(0);
    webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

The solution is to set a android:layerType="software" attribute on the webview in the .xml layout resource.

    <WebView
        android:id="@+id/webviev"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:layerType="software" />
提笔落墨 2025-01-03 05:51:10

避免这种情况的一种方法是取消选中“强制 GPU 渲染”,

    Settings -> Developer Options -> Force GPU Rendering

但这并不能解决问题。我已经在模拟器中尝试过这段代码并且它有效。通过使用软件而不是硬件加速来强制 webview 渲染。

    webview.setBackgroundColor(Color.TRANSPARENT);
    webview.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

它能解决您的问题吗?

One way to avoid this is to uncheck "Force GPU Rendering" in

    Settings -> Developer Options -> Force GPU Rendering

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.

    webview.setBackgroundColor(Color.TRANSPARENT);
    webview.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

Does it solve your problem?

负佳期 2025-01-03 05:51:10

尝试使用此代码来传输 webview

webView.setBackgroundColor(Color.TRANSPARENT);

try this code to transprent webview

webView.setBackgroundColor(Color.TRANSPARENT);
兲鉂ぱ嘚淚 2025-01-03 05:51:10

尝试调用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文