5

Recently, I implement webbased-application on Android. I want to make webview's background color Transparent.

Searching, i've found that two lines for Webview.

newWebView.setBackgroundColor(0x00000000);                  
newWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

It works for Android version 4.0~4.3, but does not work for 4.4 KITKAT.

I got just white-background. Addtionally, when i set background color, black, shown below :

newWebView.setBackgroundColor(Color.BLACK);

Also I saw white-background. Is there anybody knows the solution ?

Stern
  • 61
  • 1
  • 2
  • Go to this [http://stackoverflow.com/questions/20675554/webview-rendering-issue-in-android-kitkat](http://stackoverflow.com/questions/20675554/webview-rendering-issue-in-android-kitkat) – M D May 24 '14 at 08:17
  • that posting does not work for me :( – Stern May 24 '14 at 08:24
  • try setting the alpha tag of the webview itself I dont know if it exists though – Illegal Argument May 24 '14 at 08:25
  • 1
    @IllegalArgument .setAlpha() method works, you know, it makes every element on the webview transparent, so it's not what i want – Stern May 24 '14 at 08:31

2 Answers2

4

This might help you

    webView.setBackgroundColor(0x00000000);
if (Build.VERSION.SDK_INT >= 11) webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

this.wv.setWebViewClient(new WebViewClient()
{
    @Override
    public void onPageFinished(WebView view, String url)
    {
        view.setBackgroundColor(0x00000000);
        if (Build.VERSION.SDK_INT >= 11) view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
    }
});

Source : http://premius.net/blog/andoid/118-android-webview-transparent-background-for-android-2-3-and-4-x.html

mustafa96m
  • 329
  • 3
  • 16
1

works for android 6 (for me), see previous answer

            wv.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    view.setBackgroundColor(ContextCompat.getColor(context, R.color.transparent));
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                    } else {
                        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
                    }
                }
            });
            wv.setBackgroundResource(android.R.color.transparent);
VKDev
  • 604
  • 7
  • 18