0

Is there a way to make a WebView transparent (so the user can see through it to the view behind), until it's (non-transparent) content has loaded content?

mWebView.setBackgroundColor(Color.TRANSPARENT); works temporarily, but unfortunately the WebView becomes non-transparent fairly soon after the content starts loading.

The equivalent approach works on iOS.

Andrew Ebling
  • 10,175
  • 10
  • 58
  • 75

3 Answers3

0

Simply not showing your webview until the content has loaded should have the same effect. Something along these lines: How to listen for a WebView finishing loading a URL?

Stephen
  • 4,041
  • 22
  • 39
0

@stephen's answer seems to be in right direction.

However, you can try one more approach. Make your layout structured like this

<FrameLayout>
   <WebView>
   <RelativeLayout> --> Rest Layout here
</FrameLayout>

Now as RelativeLayout is added after WebView, it will be visible on top of WebView, Once your webpage is fully loaded, you can hide RelativeLayout like this

mWebView.setWebViewClient(new WebViewClient() {
   public void onPageFinished(WebView view, String url) {
        // hide RelativeLayout here...
    }
});
Akhil
  • 6,667
  • 4
  • 31
  • 61
0

I've achieved this effect by using setting the alpha value of a parent layout of the webview element to 0.01f, might work also directly on the Webview.

view.setAlpha(0.01f);

and then setting the alpha to 1 when webview finished loading in onPageFinished.

Setting the visibility to Gone/Hidden stops the Webview.

Raanan
  • 4,777
  • 27
  • 47