2013-05-07 146 views
0

我試圖在加載Webview中的內容時顯示progressDialog。完成後,progressDialog將被解除。點擊Webview加載的Android進度對話框 - 空白屏幕

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有什麼問題?

感謝

回答

1

試試這個爲網頁視圖客戶

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(); 
       } 
      } 

     }); 
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(); 
         } 
        } 

     }); 
    }