Android:加载WebView后无法关闭ProgressDialog

时间:2016-07-18 12:19:01

标签: android android-webview progressdialog

加载WebView后无法关闭进度对话框

这是代码

webview.setWebViewClient(new WebViewClient() {

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
            public void onLoadResource (WebView view, String url) {
                if (progressDialog == null) {
                    progressDialog = new ProgressDialog(activity);
                    progressDialog.setMessage("Chargement en cours");
                    progressDialog.show();
                }
            }
            public void onPageFinished(WebView view, String url) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;
                }
            }
        });
webview.loadUrl("http://www.someexample.com");

4 个答案:

答案 0 :(得分:1)

尝试覆盖所有功能

 webview.setWebViewClient(new WebViewClient() {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {              
        view.loadUrl(url);
        return true;
    }
    @Override
    public void onLoadResource (WebView view, String url) {
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(activity);
            progressDialog.setMessage("Chargement en cours");
            progressDialog.show();
        }
    }
    @Override
    public void onPageFinished(WebView view, String url) {
        if (progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }
}); 

webview.loadUrl( “http://www.someexample.com”);

答案 1 :(得分:0)

您可以执行以下操作:

<style> table colgroup{col{align:right}col{align:right }col{align:left }}  </style>

答案 2 :(得分:0)

创建进度对话,例如

ProgressDialog progressDialog= ProgressDialog.show(this, "", "Loading...",true);

onPageFinished就像

 public void onPageFinished(WebView view, String url) {
     if (progressDialog != null)
         if (progressDialog.isShowing())
             progressDialog.dismiss();
 }

答案 3 :(得分:0)

试试这个会起作用

protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            webview = (WebView) findViewById(R.id.activity_main_webview);
            WebSettings webSettings = webview.getSettings();
            webSettings.setJavaScriptEnabled(true);

            webview.loadUrl("https://someexample.com");
            webview.setWebViewClient(new WebViewClient() {


                public void onLoadResource (WebView view, String url) {
                    if (progressDialog == null) {
                        progressDialog = new ProgressDialog(MainActivity.this);
                        progressDialog.setMessage("Chargement en cours");
                        progressDialog.show();
                    }
                }

                public void onPageFinished(WebView view, String url) {

                    progressDialog.dismiss();
                    //hide loading image
                   // findViewById(R.id.progressBar1).setVisibility(View.GONE);
                    //show webview
                    findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
                }
            });
        }
    }