You can set the "clickable" attribute to "true" in the layout that your ProgressBar contains:
<FrameLayout android:id="@+id/progressBarContainer" android:layout_height="match_parent" android:layout_width="match_parent" android:clickable="true" > <ProgressBar android:id="@+id/progressBar" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" /> </FrameLayout>
Then, while the ProgressBar is displayed, its container (which fills the entire screen, although invisible) will intercept any click events so that they do not fall into the base layout while your ProgressBar is displayed.
To use this, do this when you want to show the ProgressBar:
findViewById(R.id.progressBarContainer).setVisibility(View.VISIBLE);
and then do it when done:
findViewById(R.id.progressBarContainer).setVisibility(View.INVISIBLE);
For example, if you use this in AsyncTask, you can make it visible in onPreExecute (), and then make it invisible in onPostExecute ().
source share