MainActivity.kt
package com.cfsuman.kotlintutorials
import android.app.Activity
import android.app.AlertDialog
import android.os.Bundle
import android.widget.*
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val context:MainActivity = this
// get the widgets reference from XML layout
val button = findViewById<Button>(R.id.button)
// create a builder for an alert dialog with theme resource
button.setOnClickListener {
val builder = AlertDialog.Builder(
context,
android.R.style.Theme_Material_Light_NoActionBar_Fullscreen
)
builder.setTitle("Full Screen Dialog Title")
builder.setMessage("\n\nThis is an example message." +
"\n\n\n\n\n\n\n\n\n\n\n\n\n\nSecond Text." +
"\n\n\n\n\n\n\n\n\nThird Text." +
"\n\n\n\n\n\n\n\n\n\n\n\n\n\nFourth Text.")
builder.setPositiveButton("Yes"){ dialog,which->
// do something on positive button click
}
builder.setNegativeButton("No"){dialog,which->
// do something when negative button clicked
}
builder.setNeutralButton("Cancel"){dialog,which->
// do something on neutral button click
}
val dialog = builder.create()
dialog.show()
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DCDCDC"
android:padding="24dp">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Full Screen Alert Dialog"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle dependencies[add]
// Material components
implementation 'com.google.android.material:material:1.6.1'
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilu6vYaNDPNLbKx32GirOfQPo4g4axVTmyFQ-5IqSxDrixSrVj7B51e_FKp7EDqHAJHpsBA6ZV9p1-90zT5RO8h4QsrtYu_FQaHw7p7GftZEgJjV-blHsNJPUFYRefwMQ39huk5qcaoVARXS5F6Xb2i7r0luY07BSWRGl716RNba-F_Wf4mUqyFcF3UQ/s1600/android_kotlin_full_screen_alert_dialog_example.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf14FtoQ7fPJ7RsI0uuZ9n7IKPcx4ydRD547zodrznTGjVAZD1bmLYUK3eh0zawsjA0xvpai5P54U2kC13PnCe8yWRME7JQF2GUUsRA-hj1cw8UmDaHiHMwxfX0ZmV8ZhobY-06YiuajYVOA8iK6baXVbqdpCyoe45wpa6AE3hG0j9uLXFt_9fmcPhOg/s1600/android_kotlin_full_screen_alert_dialog_example2.png)