Puneet Kushwah
Puneet Kushwah

Reputation: 1600

White background while switching to webview

I have a button, onclick of that button a webview load a html from asset, it takes a while to load that html page, so in between a while color appears, in short words while switching to webview white color comes in background, i researched a lot but not got any thing.

How to fix ??? Kindly help.

Upvotes: 3

Views: 2508

Answers (1)

bonnyz
bonnyz

Reputation: 13548

Try to set the background color to the WebView:

webview.setBackgroundColor(0x01000000);

EDIT: if you want a black color:

webview.setBackgroundColor(0xFF000000);

If this doesn't work for you, I suggest you this workaround:

  1. Add the WebView inside a container (like a FrameLayout) and the set the background of the container to black
  2. Turn the WebView INVISIBLE when you need to load a new page
  3. Attach a custom WebViewClient to the your WebView using setWebViewClient(). Your custom WebViewClient will set the WebView visible again when the page is loaded. During the load process, you will see a black background.
  webView.setWebViewClient(new InternalWebViewClient());
  //...
  private class InternalWebViewClient extends WebViewClient {

     @Override
     public void onPageFinished(WebView view, String url) {
        super.onPageFinished( view, url );
        webView.setVisibility(View.VISIBLE);
     }
  }

Upvotes: 4

Related Questions