onPageStarted和onPageFinished不起作用

时间:2015-03-06 11:16:22

标签: java android android-webview

这是我的代码段:

webView = (WebView) browserView.findViewById(R.id.webView);
webView.loadUrl(webUrl);

    webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
         if (url.contains("some_domain")) {
             webView.loadUrl(url);
             Toast.makeText(context, "Loaded", Toast.LENGTH_SHORT).show();
         } else
             Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
             return true;
         }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        progressBar.setVisibility(View.GONE);
    }
});

方法onPageStartedonPageFinished仅在我第一次点击链接时执行。然后,这些方法不起作用。可能是什么问题?

感谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试将shouldOverrideUrlLoading方法更改为

@Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
                progressBar.setVisibility(View.VISIBLE);
            webView.loadUrl(url);
            return true;

        }