How do I call a progressBar within Dialog?

1

I would like to know if there is any way to call a ProgressBar within an AlertDialog ... If so, how do I?

    
asked by anonymous 17.08.2017 / 21:08

1 answer

4

Here's an example:

  private Dialog mDialog;

    public void openDialog(){
        mDialog = new Dialog(this);
        //vamos remover o titulo da Dialog
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //vamos carregar o xml personalizado
        mDialog.setContentView(R.layout.dialog);
        //DEixamos transparente
        mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        // não permitimos fechar esta dialog
        mDialog.setCancelable(false);
        //temos a instancia do ProgressBar!
        final ProgressBar progressBar = ProgressBar.class.cast(mDialog.findViewById(R.id.progressBar));


        mDialog.show();

               // mDialog.dismiss(); -> para fechar a dialog

    }
}

dialog.xml

   <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minWidth="555dp"
        android:background="#77000000">
        <LinearLayout
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textSize="22dp"
                android:textColor="#FFF"
                android:text="Aguarde..." />

            <ProgressBar
                android:id="@+id/progressBar"
               <!--ESTE FAZ COM QUE O PROGRESS BAR FIQUE RODANDO AUTOMATICAMENTE!-->
                android:indeterminate="true"
                style="?android:attr/progressBarStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" />
        </LinearLayout>
    </RelativeLayout>
    
17.08.2017 / 21:32