在工具栏中的后退按钮上设置 ProgressDialog 关闭
Set ProgressDialog dismiss on Back button In Toolbar
我的 activity 中有 ProgressDialog,我想在单击工具栏的后退按钮时关闭它。我已经添加了 OnKey 函数来处理 Phone 的 BackButton 功能并且工作正常,但是当我单击工具栏上的 BackButton 时它不起作用。
Public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
progressdialog.dismiss();
finish();
}
return true;
}
我在工具栏的后退按钮上添加了 setOnclickListener 方法,但它仅在数据从数据库中完全加载时以及 ProgressDialog 关闭以返回上一个 activity.
时有效
ProgressDilog is a modal dialog which means user cannon interact with application in any way. So it's not possible to tap on any button when dialog is displayed. Dialog can be dismissed by back button and you don't even need to subclass it and override the onKey method, you can just call correct static method for displaying .
您可能应该考虑以其他方式向用户显示进度。 ProgressDialog 已弃用。
This class was deprecated in API level 26.
ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.
我的 activity 中有 ProgressDialog,我想在单击工具栏的后退按钮时关闭它。我已经添加了 OnKey 函数来处理 Phone 的 BackButton 功能并且工作正常,但是当我单击工具栏上的 BackButton 时它不起作用。
Public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
progressdialog.dismiss();
finish();
}
return true;
}
我在工具栏的后退按钮上添加了 setOnclickListener 方法,但它仅在数据从数据库中完全加载时以及 ProgressDialog 关闭以返回上一个 activity.
时有效ProgressDilog is a modal dialog which means user cannon interact with application in any way. So it's not possible to tap on any button when dialog is displayed. Dialog can be dismissed by back button and you don't even need to subclass it and override the onKey method, you can just call correct static method for displaying .
您可能应该考虑以其他方式向用户显示进度。 ProgressDialog 已弃用。
This class was deprecated in API level 26. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.