Search code examples
androidandroid-layoutprogressdialog

How to set custom layout to progress dialog background?


Question in the title) Help me, please) I want to make from this enter image description here

that

enter image description here

I tried implement it's.

mProgressDialog = new ProgressDialog(this);
mProgressDialog.getWindow().setContentView(R.layout.footcloth);
mProgressDialog.setMessage(Constants.PROGRESS_DIALOG_MESSAGE);
mProgressDialog.show();

But this code throwing exception

java.lang.RuntimeException: Unable to start activity ComponentInfo{im.anticafe.anticafeim/im.anticafe.anticafeim.activities.HomeActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

This code implements in activity BottomBarActivity

abstract public class BottomBarActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "bottomBarActivity";
    private int mWidth;
    private ProgressDialog mProgressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.getWindow().setContentView(R.layout.footcloth);
        mProgressDialog.setMessage(Constants.PROGRESS_DIALOG_MESSAGE);
        mProgressDialog.show();
        ...
    }

    ...
}

And this activity are extending in others. So, help me solve my problem, please) Thanks)


Solution

  • There are 2 answers

    1. If you wanna change color ( transparency ) of background under Progress dialog,I recommend you to use fragments and switch them. At fragment you can set any properties and put ProgressBar

    after complete reload, you can switch back again, or to another fragment

    1. If you wanna change progress dialog

      public class TransparentProgressDialog extends Dialog {
      
        public TransparentProgressDialog(Context context) {
          super(context, R.style.TransparentProgressDialog);
      
          WindowManager.LayoutParams wlmp = getWindow().getAttributes();
      
          wlmp.gravity = Gravity.CENTER_HORIZONTAL;
          getWindow().setAttributes(wlmp);
          setTitle(null);
          setCancelable(false);
          setOnCancelListener(null);
          View view = LayoutInflater.from(context).inflate(
                  R.layout.progress_dialog, null);
          setContentView(view);
         }
      }
      

    In your activity use

    TransparentProgressDialog pd = new TransparentProgressDialog(context);
    pd.show();
    
    ....
    
    if (pd.isShowing()){
                pd.dismiss();
            }