I’ve trying for days now to get a solution to show a splash screen while loading a webview.
I’ve looked around and there are several approaches:
– make activity just to show splash screen, wait a few seconds and then start the webview activity -> this is not a solution since all the loading is again done after splash screen is closed
-
second approach is something like this:
myWebView = (WebView) findViewById(R.id.webview); myWebView.getSettings().setJavaScriptEnabled(true); myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); myWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { findViewById(R.id.webview).setVisibility(View.VISIBLE); //hide loading image findViewById(R.id.imageView1).setVisibility(View.GONE); //show webview } });This works, but again there is a slight appearance of a white screen while transitioning to webview. And also you can’t control the timing of your splash screen.
-
third solution is something that I’d like to make, but (even after few days of searching and trying) don’t know how -> show splash screen in one thread, prepare everything for a webview in another and then simply switch to webview.
My question is, can anybody show me where to start with this third solution?
- I wanted to try something like this! but I couldn’t figure out how to pass webview to another activity and from what I read, this is not even a good idea.
Any suggestion, ideas, pointers? Is there a way to show splash screen, prepare(inflate) webview in another thread and then switch to it after loading url (and everything else) is done?
Thanks!!!
Try to use a WebChromeClient on the Webview. In the WebChromeClient, you have a method onProgressChange.
You can do disappear the splash screen when the onProgressChange tell you that the page are finish to load.
Edit:
You can call in a thread your Url with HttpGet for example and retrieve the response. When you have the response you can load the webview with the loadData(…) method.