This is progress dialog util class if you need in your project. It is written in Kotlin. You can just copy the code and paste inside you own class and use it straight out of the box. Just pass context and message. Also, you can adjust the position, color, padding and style inside this class. Everything is done grammatically. The dialog is set not to be canceled if clicked outside it.


And to use it just call setProgressDialog function and add context and message, like this:

This is how it looks like:

Spread the love


  1. Hi, thanks for the code.
    I have this error:

    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: , PID: 23828
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{/.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.res.Resources android.content.Context.getResources()’ on a null object reference

    and the line of the null is:
    val linearLayout = LinearLayout(context)
    (line 17)

    could you have some idea why this error?

    1. Author

      Hi, Franco

      Thanks for reaching us.

      In MainActivity in your onCreate function, put your dialog ( ProgressDialogUtil.setProgressDialog(this, “Loading…”) ) after setContentView(R.layout.activity_main) line.

      this keyword points to your MainActivity, and this will be null before onCreate function is called.

      If you have any issues, please feel free to ask.


      1. Thanks! now it shows, but how can I call it out outside the onCreate function?

        1. Thanks now it shows, but how can I call it outside the onCreate function? I mean to hide the dialog from another function.

Leave a Reply
