我尝试在onPageStarted期间创建一个Progress对话框并在onpageFinished时关闭,但在页面加载后仍然在webview中显示Progress对话框

时间:2011-10-05 13:27:02

标签: java android dialog webview progressdialog

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.webviewactivity);        
    WebView webview=(WebView)findViewById(R.id.webViewActivityWebView);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebChromeClient(new WebChromeClient()
    {
        @Override
    public void onProgressChanged(WebView view, int newProgress) {
        super.onProgressChanged(view, newProgress);
    value=newProgress;
    activity.setTitle("Loading..");
    activity.setProgress(newProgress*100);
    if(newProgress==100)
    {           
        activity.setTitle(R.string.app_name);

    }               
    }           
    });

webview.setWebViewClient(new WebViewClient(){

 @Override
  public void onReceivedError(WebView view, int errorCode,
             String description, String failingUrl) {
        activity.setTitle("Error On Page");         
}

public void onPageStarted(WebView view, String url, Bitmap favicon) {
     loadDialog();
    }
public void onPageFinished(WebView view, String url) {
    progressDialog.dismiss();
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
 view.loadUrl(url);

            return true;
        }           
    });      
    webview.loadUrl("http://www.google.com");
}
public void loadDialog()
{       
    progressDialog=ProgressDialog.show(this, "Loading", "Please Wait", true, true);     
}

0 个答案:

没有答案