WebView不在onPageFinished时删除进度条

时间:2012-08-30 07:05:40

标签: android webview progress-bar

我有一个activity在启动时显示ProgressDialog,当WebView上的页面加载完毕后,它会消失。我在onPageFinishedprogbar.dissmiss()上登录,但只有日志正在运行且ProgressBar仍然存在。我的代码是这样的:

ProgressDialog progbar;
progbar = ProgressDialog.show(SchoolActivity.this, "", "Loading...");
wv.setWebViewClient(new WebViewClient(){                
@Override
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(wv, link);
    Log.d("log","Finished!!!");
    progbar.dismiss();
    }
}
});

wv.loadUrl(link); //"wv" is the webview and "link" is the url

1 个答案:

答案 0 :(得分:1)

这对我有用:

private void initializeWebView() {
        // fix weird recursive-loop bug in WebView
        final ProgressDialog dialog = new ProgressDialog(Activity.this);
        dialog.setMessage("Please wait while the form is loading...");
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.show();

        wv.setWebViewClient(new WebViewClient() {
            @Override           
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            public void onPageFinished(WebView view, String url) {
                dialog.dismiss();
           }
        });
}