개발/Android

AlertDialog ProgressBar

Dallaenae 2021. 12. 8. 21:31

res > layout > progress.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:padding="13dp"
    android:layout_centerHorizontal="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        android:id="@+id/loader"
        android:layout_marginEnd="5dp"
        android:layout_width="45dp"
        android:layout_height="45dp" />
    <TextView
        android:layout_width="wrap_content"
        android:text="Connecting..."
        android:textAppearance="?android:textAppearanceSmall"
        android:layout_gravity="center_vertical"
        android:id="@+id/loading_msg"
        android:layout_toEndOf="@+id/loader"
        android:layout_height="wrap_content" />

</LinearLayout>

 

MainActivity.java

Dialog progressdialog;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(R.layout.progress);
    // This should be called once in your Fragment's onViewCreated() or in Activity onCreate() method to avoid dialog duplicates.
    progressdialog = builder.create();
    
}

//   This method is used to control the progress dialog.
public void setDialog(boolean show){
    if (show)progressdialog.show();
    else progressdialog.dismiss();
}

 

https://stackoverflow.com/questions/45373007/progressdialog-is-deprecated-what-is-the-alternate-one-to-use

반응형