Android: how to disable controls during progress bar is active

拟墨画扇 提交于 2019-12-06 18:05:28

问题


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)

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.

Simply disabling all controls is not possible because when disabling an EditText, also the keyboard is closed automatically by Android.

Any ideas how to prevent user input during the background work?

Thanks,

Chris


回答1:


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();  



回答2:


try putting progressDialog.setcancelable(false);




回答3:


You are trying to set just the Property of Activity. Instead Bring up a dialog using ProgressDialog, so that Ui will not be accessible

ProgressDialog dialog = ProgressDialog.show(this, "", "Please wait...", true);

Edit: If you do not want to use ProgressDialog, get the Root Layout and call

layout.setEnabled(false)



回答4:


in case, if somebody else faced the same problem,

to disable editing the text use: EditText.setFocusable(false);

to enable editing: EditText.setFocusableInTouchMode(true);



来源:https://stackoverflow.com/questions/12300796/android-how-to-disable-controls-during-progress-bar-is-active

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!