Android 如何将透明html加载到具有背景的webview中

Android 如何将透明html加载到具有背景的webview中,android,html,css,webview,Android,Html,Css,Webview,我正在将html页面加载到web视图中,html页面的背景颜色为灰色,web视图的背景图像为灰色。当我将html页面加载到web视图中时,我希望图像在html背景透明的情况下可见。我将如何使灰色成为透明的颜色,以便图像可见 请看下面我的html页面代码,请帮助我 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org > <html xmlns="http://www

我正在将html页面加载到web视图中,html页面的背景颜色为灰色,web视图的背景图像为灰色。当我将html页面加载到web视图中时,我希望图像在html背景透明的情况下可见。我将如何使灰色成为透明的颜色,以便图像可见

请看下面我的html页面代码,请帮助我

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org >
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
<title>html page</title>

<style type="text/css">
    .show
    {
        display: inline;
    }
    .hide
    {
        display: none;
    }
    body.class
    {
        background: #444;
        font-family: Helvetica, sans-serif, Verdana, Arial;
        opacity:0.4;
        color: #FFF;
        margin: 30px 30px 0px 30px;
        width: auto;
    }
    h1
    {
        font-size: 18px;
        font-weight: normal;
        margin: 25px 0px 10px 0px;
    }
    h2
    {
        font-size: 36px;
        margin: 15px 0px 10px 0px;
        font-weight: normal;
    }
    .author-pic
    {
        width: 200px;
        height: 200px;
        margin: 0px 0px 0px 0px;
    }
    p
    {
        line-height: 17px;
    }
</style>
<script language="javascript" type="text/javascript">
    $(function ()
</script>

您可能需要在收到HTML时对其进行更改,本例使用JSoup(主要是因为我在下载的文件文件夹中有它)

公共类SomeSortoActivityNameGoesher扩展活动{
静态最终整数超时=30000;
网络视图mView;
异步任务加载;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mView=新的网络视图(此);
mView.setBackgroundColor(Color.TRANSPARENT);
LinearLayout布局=新的LinearLayout(本);
layout.addView(mView,新的LinearLayout.LayoutParams(LayoutParams.FILL\u父级,LayoutParams.FILL\u父级));
布局。背景颜色(颜色。红色);
setContentView(布局);
mLoad=newasynctask(){
@凌驾
受保护字符串[]doInBackground(字符串…参数){
试一试{
Document doc=Jsoup.parse(新URL(“http://www.stackoverflow.com(),超时);
元素体=文档选择(“体”).first();
body.attr(“样式”,“背景色:透明”);
返回新字符串[]{doc.baseUri(),doc.outerHtml(),“text/html”,null,null};
}捕获(格式错误){
}捕获(IOE异常){
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串[]结果){
如果(结果!=null){
mView.loadDataWithBaseURL(结果[0],结果[1],结果[2],结果[3],结果[4]);
//注意:这里或多或少需要再次调用。
mView.setBackgroundColor(Color.TRANSPARENT);
}否则{
//这里有奇妙的错误处理
}
}
}.execute();
}
}

此示例应加载stackoverflow.com页面并将其变为半透明,并允许保持WebView的LinearLayout中的红色“闪耀”。至少应该在ICS上工作。

您好,只需检查下面的简单代码,您就会知道如何在类中为各种浏览器插入值

 body.class {
    /* Required for IE 5, 6, 7 */
    /* ...or something to trigger hasLayout, like zoom: 1; */
    width: 100%; 

    /* Theoretically for IE 8 & 9 (more valid) */   
    /* ...but not required as filter works too */
    /* should come BEFORE filter */
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";

    /* This works in IE 8 & 9 too */
    /* ... but also 5, 6, 7 */
    filter: alpha(opacity=50);

    /* Older than Firefox 0.9 */
    -moz-opacity:0.5;

    /* Safari 1.x (pre WebKit!) */
    -khtml-opacity: 0.5;

    /* Modern!
    /* Firefox 0.9+, Safari 2?, Chrome any?
    /* Opera 9+, IE 9+ */
    opacity: 0.5;
}

Jens谢谢你的帮助,但是我该如何修改我的html页面?你能建议我吗?在这种情况下,你需要包含更多的html文档。我提供的示例将在HTML文档中找到标记并在其上设置透明样式。
 body.class {
    /* Required for IE 5, 6, 7 */
    /* ...or something to trigger hasLayout, like zoom: 1; */
    width: 100%; 

    /* Theoretically for IE 8 & 9 (more valid) */   
    /* ...but not required as filter works too */
    /* should come BEFORE filter */
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";

    /* This works in IE 8 & 9 too */
    /* ... but also 5, 6, 7 */
    filter: alpha(opacity=50);

    /* Older than Firefox 0.9 */
    -moz-opacity:0.5;

    /* Safari 1.x (pre WebKit!) */
    -khtml-opacity: 0.5;

    /* Modern!
    /* Firefox 0.9+, Safari 2?, Chrome any?
    /* Opera 9+, IE 9+ */
    opacity: 0.5;
}