ProgressDialog is deprecated.What is the alternate one to use?

后端 未结 17 1042
面向向阳花
面向向阳花 2020-11-27 09:11

I have come across to see that ProgressDialog is now deprecated. What would be alternate one to use in place of that apart from ProgressBar. I am

17条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 09:56

    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

    
    
    
    
    
    

    In your code: Just do var dialog = ProgressDialog.progressDialog(context)

    To show: dialog.show()

    To hide: dialog.dismiss()

提交回复
热议问题