我在我的Android应用程序中有一个webview和一个显示活动的进度条。但是ProgressBar只显示应用程序加载网址后第一次如果我点击webview进度条中的链接没有显示!这是我的代码。
在OnCreateView
中dialog = (ProgressBar) v.findViewById(R.id.progressBar1);
dialog.setVisibility(View.VISIBLE);
和
private class MyWebClient extends WebViewClient {
public void onPageFinished(WebView view, String url) {
dialog.setVisibility(View.INVISIBLE);
}
}
答案 0 :(得分:0)
private void startWebView(String url) {
if (Utils.isConnectedToInternet(this)) {
progressDialog = null;
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if (progressDialog == null) {
progressDialog = progressDialog.show(PurchaseActivity.this, "", "Loading...", true, false);
}
}
//If you will not use this method url links are opeen in new brower not in webview
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
try {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
// Javascript inabled on webview
webView.getSettings().setJavaScriptEnabled(true);
// Other webview options
/*
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setBuiltInZoomControls(true);
*/
/*
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
*/
//Load url in webview
webView.loadUrl(url);
} else {
messages.showErrorInConnection(this);
}
}