在Webview中加载页面后无法关闭“进度”对话框

时间:2018-03-20 04:48:29

标签: android webview progressdialog

当我将此ProgressDialog添加到我的Webview应用中时,任何人都可以帮助我工作正常但是当页面加载时progress dialog没有被解雇,任何人都可以帮助我我使用这个Fragment

中的代码
public static ProgressDialog progressDialog;

     mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                    swipeRefreshLayout.setRefreshing(true);
                    progressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");

                    super.onPageStarted(view, url, favicon);

                }


                public void onPageFinished(WebView view, String url) {
                    swipeRefreshLayout.setRefreshing(false);
                    getActivity().setTitle(view.getTitle());
                    if(progressDialog!=null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    super.onPageFinished(view, url);

                }
            });

现在感谢所有帮助我的人编辑的代码

public static ProgressDialog progressDialog;

//Under onCreate View
progressDialog = ProgressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");

mWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                swipeRefreshLayout.setRefreshing(true);
                super.onPageStarted(view, url, favicon);

            }


            public void onPageFinished(WebView view, String url) {
                swipeRefreshLayout.setRefreshing(false);
                getActivity().setTitle(view.getTitle());
                if(progressDialog!=null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog.hide();
                }
                super.onPageFinished(view, url);

            }
        });

3 个答案:

答案 0 :(得分:0)

onPageStarted()方法移出以下行,因为它将针对每个基础网址进行调用,除非每个cssjs文件都已加载,否则它将继续显示

progressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");

答案 1 :(得分:0)

确保if(progressDialog!=null && progressDialog.isShowing())此条件返回true。在那里设一个断点并确保它们都是真的。

 progressDialog.hide() 

答案 2 :(得分:0)

请试试这段代码

progressDialog = ProgressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");

希望有所帮助