Skip to content Skip to sidebar Skip to footer

Transparent Webview In Xamarin

I searched Transparent WebView but I could not find any answer for my problem. I have these: string str = 'Hello. How are you? I am fine.'; String s = '

Solution 1:

1) Do not set a background color in the layout axml:

<android.webkit.WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/webView" />

2) Set the background color in html:

<bodystyle='background-color:#00000000;'>

3) Set the background color of the WebView at runtime:

WebView.SetBackgroundColor(Color.Transparent);

4) This should work on most API level and WebView version combinations, if you find a combination that does not work you will also need to turn of hardware acceleration, but typically this is only needed for old API version (i.e. 2.x/3.x...) and I would typically not recommend in turning acceleration off...

WebView.SetLayerType(LayerType.Software, null);

Example:

string htmlContent = "Hello. How are you? I am fine.";
string htmlString = @"
    <html>
        <head>StackOverFlow</head>
        <body style='background-color:#00000000;'>
            <div>
                " + htmlContent + @"
            </div>
        </body>
    </html>
";
webview.SetBackgroundColor(Color.Transparent);
webview.LoadDataWithBaseURL("", htmlString, "text/html", "UTF-8", null);

Post a Comment for "Transparent Webview In Xamarin"