0

在 Webview 中加载内容时,我尝试显示 progressDialog。完成后,progressDialog 将被关闭。

private ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient(){

        @Override
        public void onLoadResource (WebView view, String url) {
            //show progress bar
            if (progressDialog == null) {
                progressDialog = new ProgressDialog(activity);
                progressDialog.setMessage("Loading please wait...");
                progressDialog.show();
            }   
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }

    });
}

我有 2 台测试设备 Android 2.3.6 和 Android 4.0。在 Android 2.3.6 中,完全没有问题。对于 Android 4.0 平板电脑,在显示进度对话框时,点击它会隐藏或删除 progressDialog,并使屏幕变为空白。

我的progressDialog有什么问题?

谢谢

4

2 回答 2

1

试试这个作为你的 webView 客户端

 webView.setWebViewClient(new WebViewClient(){

            @Override
            public void onLoadResource (WebView view, String url) {
                //show progress bar
                if (progressDialog == null) {
                    progressDialog = new ProgressDialog(MainActivity.this);
                    progressDialog.setMessage("Loading please wait...");
                    progressDialog.show();
                    progressDialog.setCanceledOnTouchOutside(false);
                    progressDialog.setCancelable(false);
                }   
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
            }

        }); 
于 2013-05-08T09:35:45.113 回答
0
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        WebView webview = (WebView) findViewById(R.id.webView1);
        webview.loadUrl("http://google.com");
        final ProgressDialog pd = ProgressDialog.show(this, "please wait", "Loading...");
        webview.getSettings().setBuiltInZoomControls(true);
        webview.setWebViewClient(new WebViewClient() {
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {              
                        view.loadUrl(url);
                        return true;
                    }


                  public void onPageFinished(WebView view, String url) {
                        if (pd.isShowing()) {
                            pd.dismiss();
                        }
                    }

        });
    }
于 2013-09-13T15:32:47.130 回答