每次 WebView 进入 link 时不会显示进度条
Progressbar dose not show every time WebView goes to a link
我的 android 应用程序中有一个 webview 和一个显示 activity 的进度条。但是 ProgressBar 只在应用程序加载 url 时第一次显示,之后如果我在 webview 中点击 link progressbar 不会显示!这是我的代码。
在 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);
}
}
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);
}
}
我的 android 应用程序中有一个 webview 和一个显示 activity 的进度条。但是 ProgressBar 只在应用程序加载 url 时第一次显示,之后如果我在 webview 中点击 link progressbar 不会显示!这是我的代码。
在 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);
}
}
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);
}
}