Диалог прогресса устарел, я создал пользовательский класс в Kotlin:
class ProgressAlert(private val context: Context) {
private lateinit var builder: AlertDialog.Builder
private lateinit var dialog: AlertDialog
var message = "Loading..."
var color = Color.BLUE
fun show() {
builder = AlertDialog.Builder(context)
builder.setView(layoutInitializer())
dialog = builder.create()
dialog.show()
}
fun dismiss() {
dialog.dismiss()
}
private fun layoutInitializer(): View {
//Create LinearLayout Dynamically
val layout = LinearLayout(context)
//Setup Layout Attributes
val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
layout.layoutParams = params
layout.gravity = Gravity.CENTER_VERTICAL
layout.orientation = LinearLayout.HORIZONTAL
layout.setPadding(16, 30, 30, 16)
// Add elements:
val progressBar = ProgressBar(context, null, R.attr.progressBarStyleLarge)
progressBar.isIndeterminate = true
progressBar.visibility = View.VISIBLE
progressBar.indeterminateTintList = ColorStateList.valueOf(color)
//Create a TextView to add to layout
val textview = TextView(context)
textview.setTextSize(TypedValue.COMPLEX_UNIT_SP, (16).toFloat())
textview.setPadding(50, 0, 0, 0)
textview.text = message
layout.addView(progressBar)
layout.addView(textview)
return layout
}
}
Используя:
private val loader = ProgressAlert(this)
И установил его:
loader.run {
color = Color.BLUE
message = "Wait a few seconds..."
}
И показать / отклонить это:
loader.show()
loader.dismiss()