问题
This is more of a visual thing than a direct issue, but when a WebView loads in my application, the screen is blank white for between 2-4 seconds until the content is fully loaded. The time is dependent on the size of content that is loading.
Is there a way to manage this, so that the screen will only refresh to the content when loaded? Something like a "loading..." animation or something similar? I just do not want the plain white screen presented to my users.
I have a splash screen that then loads the WebView. The WebView works fine after that initial blank pause (while loading), but I would like to hold it on a particular screen until the page has loaded or have a black screen with a progress loader.
Is there something that detects a load complete perhaps? If that were the case, I could use it as a trigger.
Does anyone know of a way to manage this blank white screen?
Thanks!
/r
回答1:
Maybe you can take a look at this previous issue.
How to listen for a WebView finishing loading a URL?
回答2:
You could alternatively make the webview transparent:
webview.setBackgroundColor(0x00000000);
回答3:
Simply put this code in onCreate
ProgressDialog _dialog ;
my_web_view.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
_dialog =ProgressDialog.show(Store_locator.this, "", "Please wait...");
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
_dialog.dismiss();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
try{
_dialog.dismiss();
}catch (Exception e) {
// TODO: handle exception
}
}
});
回答4:
the answer to this is that there's no good answer. what you want, as you stated, is that the webview shows the current content until the new content is loaded ... just like a normal browser. it won't do that.
you can show loading animations, but it's still not a good user experience. if you make a full-screen type of animation, the user is jarred with flashing screens. if you make a browser-type progress at the top / bottom, it looks odd because you still have most of the page white.
回答5:
To manage blank white screen what you can do is set a proper background colour (not white) to your layout xml , make the visibility of the webview gone in the layout xml file and add a webviewclient to it and whenever the load of the URL is completed the set the webview's visibility to visible.
public void onPageFinished(WebView view, String url) {
// do your stuff here
webView.setVisibility(View.VISIBLE);
}
});
回答6:
webView.setBackgroundColor(Color.TRANSPARENT) removes the white screen for webview
来源:https://stackoverflow.com/questions/5304171/how-to-manage-the-blank-white-loading-screen-of-an-android-webview