Jason Jason - 2 months ago 27
Android Question

Disable a whole activity from user action

Is there a simple way to disable a user interacting with an activity.
To be done when there is an action running (and a spinning progress bar in the title bar)

EDIT: As it seems I was not clear enough I meant to say: while I already have a spinning progress bar, the user is still able to push any button on the activity, I want to disable the user from being able to do that while the task is running. I do not want to however disable each item on the screen one by one.

Thanks, Jason

Answer

In order to block user touch events, use:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

To get touch events back, use:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

EDIT: If you want to add a feature of disable and greyed out display, you need to add in your xml layout file a linear layout that fills the parent. Set its background to #B0000000 and its visibilty to Gone. Than programicly set its visibility to Visible.

Comments