简体   繁体   English

Monodroid中的透明WebView,Android 4.0+

[英]Transparent webview in monodroid, android 4.0+

I'm trying to make my webview transparent. 我正在尝试使我的Web视图透明。

Right now my webview looks like this in xml: 现在,我的Web视图在xml中如下所示:

I have set the background to transparent, but it doesn't work. 我已将背景设置为透明,但它不起作用。 Then I found this post, tried it, but doesn't work either: Monodroid Transparent WebView 然后,我找到了这篇文章,尝试了一下,但是也不管用: Monodroid Transparent WebView

My webview just turned black. 我的网络视图刚刚变黑。

I'm testing on my Nexus 5 with Android 4.4.4, and the WebView background is still black setting color: 我正在使用Android 4.4.4的Nexus 5进行测试,并且WebView背景仍然为黑色设置颜色:

mWeb.SetBackgroundColor(Color.Transparent); 

OR 要么

mWeb.SetBackgroundColor(new Color(0x00000000)); 

OR 要么

mWeb.SetBackgroundColor(Color.Transparent); 
mWeb.SetBackgroundDrawable(null); 
mWeb.SetBackgroundResource(0);

But if I test it on a device with android 2.3, it works! 但是,如果我在装有Android 2.3的设备上对其进行测试,则可以正常工作! So what to do on devices running 4.0+? 那么在运行4.0+的设备上该怎么办?

My HTML-code look like: 我的HTML代码如下所示:

<html>
    <head>
        <meta name="viewport" content="target-densitydpi=device-dpi" />
        <style>
            h1
            {
                font-weight:700;
            }
            html
            {
                background-color:transparent;
            }

            ul
            {
                padding:0 20px;
            }

            li
            {
                padding:0;
                margin:0;
            }

            div
            {
                background-color:transparent;
            }
            table
            {
               border-collapse:collapse;
            } 
            table td
            {
               border:none;
               outline:none;
            }
            body
            {
                background-color:transparent;
                margin:0;
            }
        </style>
    </head>

    <body>
        // MY TEXT GOES HERE!
    </body>
</html>

Like the other answer you posted i am also using the following code to set my webview to transparent: 像您发布的其他答案一样,我也在使用以下代码将我的Web视图设置为透明:

wview.SetBackgroundColor(new Color(0,0,0,0));

It should work on devices running 4.0+. 它应该在运行4.0+的设备上运行。 But be sure that what you show in the webview is also set to use a transparent background. 但请确保您在Web视图中显示的内容也设置为使用透明背景。 - That is the body of you html and whatever js or jquery libraries you are using. -这就是您的html主体以及正在使用的任何js或jquery库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM