How do I call a progressBar inside the Dialog?

Asked

Viewed 864 times

1

I wonder if there is any way to call a Progressbar inside a Alertdialog... If so, how do I?

1 answer

5


Follow 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

    }
}

xml dialog.

   <?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>
  • Thanks a lot.... I will test and modify what I need inside XML.....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.