Search code examples
androidkotlinandroid-alertdialog

How do I change the width and height of AlertDialog in Kotlin


How do I change the height and width of my Alert dialog in Kotlin. My alert dialog code looks like this:

val loginProgressDialog = AlertDialog.Builder(this)
            .setView(layoutInflater.inflate(R.layout.alert_dialog, null))
            .setCancelable(false)
            .create()

I tried the following but it didn't work

    loginProgressDialog.window?.attributes?.width = 100
    loginProgressDialog.window?.attributes?.height = 100

If you can link to a post where there is a solution, I'd love that too.


Solution

  • You can achieve that by using this

    loginProgressDialog.window?.setLayout(100, 100)
    

    You should only use it right after showing the AlertDialog using loginProgressDialog.show()