VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-change-the-position-of-alertdialog-in-android/

⇱ How to Change the Position of AlertDialog in Android? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Change the Position of AlertDialog in Android?

Last Updated : 23 Jul, 2025

AlertDialog in android is one of the UI widgets which immediately pops up to confirm the user interaction or to confirm the action which is done by the user. In most of the applications, the position of the alert dialog is in the center. In this article, it's been discussed how to change the position of the alert dialog in android. Have a look at the following image to differentiate the normal alert dialog with the center position and the alert dialog with the changed position.

Note that we are going to implement this project using both the language Java and Kotlin

👁 Change the Position of AlertDialog in Android

Steps to implement the Alert Dialog with Different Position

Step 1: Create an empty activity project

Step 2: Working with the activity_main.xml file

  • The main layout of the application contains one button which is used to build show the alert dialog at the specified position.
  • Invoke the following code inside the activity_main.xml file to implement the UI.

activity_main.xml:

Output UI:

👁 alert-box-position-ui


Step 3: Working with the MainActivity.java file

For changing the alert dialog position at the top of the Android window, invoke the following code to implement. Comments are added for better understanding.

MainActivity File:

Output:

Comment

Explore