Android版:闪屏和web视图
我想了好几天,现在得到一个解决方案来显示启动画面加载网页视图。
I've trying for days now to get a solution to show a splash screen while loading a webview.
我环顾四周,有几种方法:
- 使活动只是为了显示开机画面,等待几秒钟,然后启动的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
}
});
这工作,但同样有一个白色的屏幕略有外观,同时过渡到web视图。而且你无法控制你的闪屏的时机。
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.
第三个解决方案是什么,我想打,但(即使在搜索和尝试的几天)不知道如何 - >显示启动画面在一个线程中,prepare一切的在网页视图另一个,然后简单地切换到网页视图。
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?
- 我想尝试一些像this!但我无法弄清楚如何的WebView传递给另一个活动,并从我读,这甚至不是一个好主意。
- 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.
任何建议,想法,指针?有没有一种方式来显示启动画面,prepare(充气)的WebView在另一个线程,然后加载URL(和其他一切)完成后切换到了吗?
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?
谢谢!
尝试使用WebChromeClient在网页视图。在WebChromeClient,你有一个方法onProgressChange。
Try to use a WebChromeClient on the Webview. In the WebChromeClient, you have a method onProgressChange.
您可以做消失闪屏时onProgressChange告诉你的页面都完成加载。
You can do disappear the splash screen when the onProgressChange tell you that the page are finish to load.
编辑:
您可以在一个线程中您的网址与调用HTTPGET例如和检索响应。当你有反应,你可以加载与loadData(...)方法的网页视图。
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.