所以我在单击列表视图中的记录后尝试加载URL,然后打开一个新活动。一切都很好......除了progressBar
显示后退按钮被禁用。我想启用它,以便它可以执行finish()
private void loadWebView(String url) {
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
progressBar = ProgressDialog.show(OtherDetailActivity.this, "Please Wait", "Loading Website...");
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(Utils.TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e(Utils.TAG, "Error: " + description);
AlertDialog.Builder builder = new AlertDialog.Builder(OtherDetailActivity.this);
builder.setTitle("Error")
.setMessage(description)
.setCancelable(false)
.setNegativeButton("Close",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
web.loadUrl(url);
}
答案 0 :(得分:5)
您需要将ProgressDialog
设置为可取消(true)。
progressBar.setCancelable(true);
setCancelable
设置此对话框是否可以使用BACK
键
如果您需要在Activity
Progress dialog dismiss
键上关闭BACK
,请添加这样的监听器和finish
Activity
。
progressBar.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
});
由于OnDismissListener
通常会在所有对话dismiss
条件中被调用,因此您可以设置OnCancelListener
仅在对话框为cancelled
progressBar.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
});