在我的应用程序中,Web视图需要一些时间来加载几个网页..是否可以显示进度,直到Web视图加载网页。我使用下面的代码来加载网页
do {
let JSON = try NSJSONSerialization.JSONObjectWithData(validData, options: options) as! [String:AnyObject]
if let error = JSON["error"] as? String {
print(error)
return .ServerError(error)
}
}
catch let error as NSError {
print(error)
}
答案 0 :(得分:0)
要显示进度条,请在Activity中的oncreateview中使用此方法:
private WebView web;
private KProgressHUD pDialog;
private void setPages() {
web = (WebView) findViewById(R.id.web);
// you can use progressbar or progressdialog or any other
// progressview here
pDialog = KProgressHUD.create(activity)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setDimAmount(0.5f);
pDialog.setCancellable(true);
pDialog.show();
web.getSettings().setSupportZoom(true);
web.getSettings().setBuiltInZoomControls(true);
web.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pDialog.dismiss();
}
});
web.loadUrl(YOUR_URL_HERE);
}