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

Unable to dismiss Progress dialog after loading a page in Webview

当我将这个 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);

            }
        });

将下面的行移出 onPageStarted() 方法,因为它将为每个基础 URL 调用,并且它将继续显示,除非每个 cssjs 文件已加载

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

确保if(progressDialog!=null && progressDialog.isShowing())这个条件returns为真。在此处放置一个断点并确保它们都为真。

尝试

 progressDialog.hide() 

你能试试这个代码吗

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

希望对您有所帮助