4.0版本如何获取webView的透明背景 [英] How to get transparent background of webView for 4.0 version

查看:16
本文介绍了4.0版本如何获取webView的透明背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一段代码,它能够在 4.0 及更高版本的 WebView 中获得透明背景.我的代码在 2.3 版上运行良好,但是当我在 4.0 和 4.2 版上运行它时,它的背景是白色的.我提供的代码适用于 2.3 版,但不适用于 4.0 和 4.2.请帮我.提前致谢...

I am looking for a piece of code which is able to get a transparent background in a WebView for version 4.0 and above. My code is working fine with version 2.3 but it is getting a white background when I run it on version 4.0 and 4.2. I am providing my code which is working for version 2.3, but not in 4.0 and 4.2. Please help me. Thanks in advance...

在 XML 中:

<WebView
    android:id="@+id/webView"
    android:layout_marginTop="6dp"
    android:layout_below="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:hardwareAccelerated ="true"        
    />

在活动文件中:

webView = (WebView) findViewById(R.id.webView);
backButton = (ImageView) findViewById(R.id.backButton);
webView.setBackgroundColor(0);                      
webView.loadUrl("file:///android_asset/Info.html");
webView.setBackgroundColor(Color.TRANSPARENT);  
/* this is used to make the background white after loading the file on screen. */

推荐答案

试试这个:

webView.setBackgroundColor(0x00000000);

并删除 android:hardwareAccelerated ="true"
因为那是题外话.

and remove android:hardwareAccelerated ="true"
as that is off-topic.

这篇关于4.0版本如何获取webView的透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆