Yes, ProgressDialog is deprecated but Dialog isn't.
You can inflate your own XML file ( containing a progress bar and a loading text) into your dialog object and then display or hide it using the show()
and dismiss()
functions.
Here is an example (Kotlin):
ProgressDialog class:
class ProgressDialog {
companion object {
fun progressDialog(context: Context): Dialog{
val dialog = Dialog(context)
val inflate = LayoutInflater.from(context).inflate(R.layout.progress_dialog, null)
dialog.setContentView(inflate)
dialog.setCancelable(false)
dialog.window!!.setBackgroundDrawable(
ColorDrawable(Color.TRANSPARENT))
return 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:background="#fff"
android:padding="13dp"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="100dp"
android:layout_margin="7dp"
android:layout_height="100dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_margin="7dp"
android:layout_toEndOf="@+id/progressBar"
android:text="Loading..." />
</RelativeLayout>
In your code:
Just do var dialog = ProgressDialog.progressDialog(context)
To show: dialog.show()
To hide: dialog.dismiss()