I am using a custom ProgressBar. Now while a task is going on, I am showing the progress bar, but user can still interact with the views and controls. How do I disable the user interaction on whole view just like a ProgressDialog does , when it is visible.
Do I need to use a transparent view on top of main view and show the progress bar on that view and hide that view once a task is completed.
Or just get the id of my parentView and set it disabled ? But then I won't be able to dim the background, just like what happens when a dialog appears on the view/Activity/Fragment. Right?
I just want to know the way to disallow the user from any interaction while the progressbar is visible.
Thanks
To disable the user interaction you just need to add the following code
To get user interaction back you just need to add the following code
Add a progress bar in your xml.Something like this
In MainActivity when a button pressed you show the progressbar and disable the user interaction.
And when user backPressed you remove the progressbar again retain the user interaction.Something like this
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
toGONE
. Then programmatically set itsvisibility
toVISIBLE
.Hope this help!
just set:
in your xml
Only this makes magic!
Make a dialog with transparent background. The issue with
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
is that when app will go in background and come back user will be able to interact with UI components, a lot more handling. So for blocking UI make a transparent dialog and if you want to set time for hide/show. Do this in a runnable thread. So the solution will beUse document default method progressbar.setCancelable(false)
I have fixed this issue by adding root layout to the
ProgressBar
.Made the root layout clickable
NOTE: In my main view, I had
RelativeLayout
as root and have added above-mentioned code inside the root layout at the last position (last child).Hope this helps!!
Make your parent layout as Relative Layout & add this :
If you have floating buttons in your UI, they still grab all the focus & remain clickable when the progress bar is visible. for this use : (when your prog bar is visible & re-enable them when you make your prog bar invisible/gone)