我的应用程序有 webview,我添加了显示加载的进度对话框,直到 web 完成加载。我在谷歌搜索并得到了很好的解决方案
wv.setWebChromeClient(new MyWebChromeClient());
wv.setWebViewClient(new MyWebViewClient());
wv.loadUrl("http://www.google.com");
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
alertdialog.setTitle("Error");
alertdialog.setMessage(description);
alertdialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//return;
finish();
}
});
alertdialog.show();
}
}
private class MyWebChromeClient extends WebChromeClient {
@Override
public void onProgressChanged(WebView view, int progress) {
progressDialog.show();
progressDialog.setProgress(0);
activity.setProgress(progress * 1000);
progressDialog.incrementProgressBy(progress);
if(progress == 100 && progressDialog.isShowing())
progressDialog.dismiss();
}
}
但我的问题是,如何让progressdialog在我启动它后只出现一次,因为现在如果我点击像图片(在google.com中)这样的例子,进度对话框会再次出现。