Android:如何在将数据加载到WebView时显示进度条?

yit*_*al9 3 android webview loaddata progress-bar

如何在将数据加载到我的webview中时显示进度条?我的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_PROGRESS);
    getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 
    this.setProgressBarVisibility(true);
    setContentView(R.layout.layout_article);
    WebView webview = (WebView) findViewById(R.id.webView);
    final Activity activity = this;
    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            activity.setProgress(progress * 100);
        }
    });

    webView.loadUrl("http://google.com");
}
Run Code Online (Sandbox Code Playgroud)

Par*_*ani 5

在调用loadData()函数之前,只需尝试显示ProgressDialog或将ProgressBar放在布局中.

WebViewClient中,只需关闭()progressDialog或使ProgressBar不可见.

例如:

// when finish loading page
public void onPageFinished(WebView view, String url) {
       if(mProgress.isShowing()) {
             mProgress.dismiss();
       }
}
Run Code Online (Sandbox Code Playgroud)

仅供参考,仅在完成Web客户端设置后调用loadData()或loadURL().

检查此示例:使用ProgressDialog加载WebView