0

Displaying an (local) image inside WebView is straightforward.

But that means it must fit within whatever my standard WebView frame has (minus title bar for example).

Before loading any page or URL into WebView I could simply achieve this by doing:

myWebView.setBackgroundColor(0);
myWebView.setBackgroundResource(R.drawable.myImage);

But after some page has been loaded and rendered, the above trick no longer works.

Is there a way to obscure WebView with a full screen image? (until a new HTML page or URL is loaded, of course)

Note: I'm not interested in a webview.loadUrl() solution.

Community
  • 1
  • 1
Eternal Learner
  • 2,602
  • 5
  • 27
  • 38

1 Answers1

2

You can set your own WebViewClient against the WebView and have it override the following two methods:

Then, when a page starts loading, toggle your image (which you overlay in e.g. an ImageView) to be visible. When loading the page has finished, set it back to either invisible or gone. This will work every time a page is loaded by the WebView.

MH.
  • 45,303
  • 10
  • 103
  • 116
  • Thanks and upvote for the creative idea. How do I toggle my image (`R.drawable.myImage`) to be visible? The only method in WebView that hints about visibility is `WebView.setVisibility(int)` and it doesn't do the trick. – Eternal Learner Jul 22 '12 at 21:26
  • Oh got it. It looks like it isn't possible to make a view out of drawable without first wrapping it a layout XML. – Eternal Learner Jul 22 '12 at 23:45
  • This won't work if you have redirects...when a redirect is loaded, it calls onPageFinished :-P – kenyee Aug 24 '16 at 17:26