我正在尝试实现一个webview加载器,但是一旦加载了页面,加载器就会显示:
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webcontent);
webView = (WebView) findViewById(R.id.webView);
final ProgressDialog progDailog = ProgressDialog.show(WebActivity.this, "Loading ","Please wait... ", true);
progDailog.setCancelable(false);
webView.setWebChromeClient(new WebChromeClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});
//webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.loadDataWithBaseURL("www.example.com", null, "text/html", "UTF-8", null);
webView.loadUrl("www.example.com");
}
我相信" onPageFinished"应该在页面加载后删除加载程序吗?
由于
答案 0 :(得分:2)
替换它:
webView.setWebChromeClient(new WebChromeClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});
由此:
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progDailog.show();
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progDailog.dismiss();
}
});
它对我有用。