Alpaslan
Alpaslan

Reputation: 233

Need a progressbar, which blocks other ui elements

I have an application that all screens are fragments and contained by the main container. I need a progressbar, which needs to block the other ui elements when it is visible. But the one below does allow the other ui elements to be clicked. How can I make it block the entire screen?

<FrameLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="false">
    <RelativeLayout
        android:id="@+id/loading_animation"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:background="@color/transparent"
        android:layout_gravity="center">
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>
</FrameLayout>

Upvotes: 0

Views: 246

Answers (3)

Pavan Bilagi
Pavan Bilagi

Reputation: 1617

Create a common class Utility to reuse the code

public class Utility {

    public static ProgressDialog getProgressDialog(Context context) {
        ProgressDialog progressDialog = new ProgressDialog(context,
                R.style.TransparentDialog);
        progressDialog.setCancelable(false);
        progressDialog
                .setProgressStyle(android.R.style.Widget_ProgressBar_Small);
        progressDialog.setProgress(0);
        return progressDialog;
    }

}

Wherever you want progress bar just use this code

protected ProgressDialog dialog;

   dialog = Utility.getProgressDialog(mContext);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setCancelable(false);
            if (dialog != null) {
                dialog.show();
            }

To dismiss dialog

           dialog.dismiss();

Upvotes: 0

Tushar Pandey
Tushar Pandey

Reputation: 4857

we have done that like :

    mDialog = new ProgressDialog(getActivity(), R.style.MyDialogTheme);
mDialog.setCancelable(false);
mDialog.show();

by using this style :

<style name="MyDialogTheme" parent="android:Theme.Holo.Dialog">
        <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textSize">12sp</item>
    </style>

Upvotes: 2

Luca Ziegler
Luca Ziegler

Reputation: 4134

add this to your relativeLayout (loading_animation):

android:clickable="true"

Upvotes: 1

Related Questions