Android:如何在进度条处于活动状态期间禁用控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12300796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: how to disable controls during progress bar is active
提问by cor
I show my infinte progress bar in the action bar "as usual":
我“像往常一样”在操作栏中显示我的无限进度条:
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
...
setProgressBarIndeterminateVisibility(true);
...
setProgressBarIndeterminateVisibility(false);
and the real work is done in a background thread (AsyncTask)
而真正的工作是在后台线程(AsyncTask)中完成的
The problem: all controls on the UI are enabled, so the user can continue to modify the underlying data before the long lasting process is finished.
问题:UI 上的所有控件都已启用,因此用户可以在持久过程完成之前继续修改底层数据。
Simply disabling all controls is not possible because when disabling an EditText, also the keyboard is closed automatically by Android.
简单地禁用所有控件是不可能的,因为禁用 EditText 时,Android 也会自动关闭键盘。
Any ideas how to prevent user input during the background work?
任何想法如何在后台工作期间防止用户输入?
Thanks,
谢谢,
Chris
克里斯
回答by Chris
What you can do is to bring up an invisible dialog and prevent it from being cancellable. It will show whatever is underneath it but disable all underlying user interaction. Then once you are done with your business you simply dismiss it and go on with your life:
您可以做的是调出一个不可见的对话框并防止它被取消。它将显示它下面的任何内容,但禁用所有底层用户交互。然后,一旦您完成了您的业务,您只需将其关闭并继续您的生活:
Dialog mOverlayDialog = new Dialog(mContext, android.R.style.Theme_Panel); //display an invisible overlay dialog to prevent user interaction and pressing back
mOverlayDialog.setCancelable(false);
mOverlayDialog.show();
回答by Aditya Nikhade
try putting progressDialog.setcancelable(false);
尝试放置 progressDialog.setcancelable(false);
回答by nandeesh
You are trying to set just the Property of Activity. Instead Bring up a dialog using ProgressDialog, so that Ui will not be accessible
您正在尝试仅设置 Activity 的属性。而是使用 ProgressDialog 调出一个对话框,这样 Ui 将无法访问
ProgressDialog dialog = ProgressDialog.show(this, "", "Please wait...", true);
Edit: If you do not want to use ProgressDialog, get the Root Layout and call
编辑:如果您不想使用 ProgressDialog,请获取 Root Layout 并调用
layout.setEnabled(false)
回答by olzhas
in case, if somebody else faced the same problem,
以防万一,如果其他人遇到同样的问题,
to disable editing the text use: EditText.setFocusable(false);
禁用编辑文本使用: EditText.setFocusable(false);
to enable editing: EditText.setFocusableInTouchMode(true);
启用编辑: EditText.setFocusableInTouchMode(true);