I'm trying to make my webview transparent.
Right now my webview looks like this in 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
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:
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! So what to do on devices running 4.0+?
My HTML-code look like:
<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:
wview.SetBackgroundColor(new Color(0,0,0,0));
It should work on devices running 4.0+. But be sure that what you show in the webview is also set to use a transparent background. - That is the body of you html and whatever js or jquery libraries you are using.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.