How to create a simple loading dialogs in Android Studio ?

 How to create a simple loading dialogs in Android Studio  ? 

Step 1 - Create a XML layout progress_layout.xml

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

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Loading..."
android:textSize="24sp" />
</LinearLayout>
Step 2 - Create Progress Dialog in onCreate Method
// for progress loading
Dialog loadingDialog;
loadingDialog = new Dialog(this);
loadingDialog.setContentView(R.layout.progress_layout);
loadingDialog.getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
loadingDialog.setCancelable(false);

// for show progress dialog
loadingDialog.show();
// for dismiss progress dialog
loadingDialog.dismiss();

Post a Comment

Previous Post Next Post