Visual Feedback: Dialogs, Snackbars & Toasts

Mar 16 2021 Kotlin 1.4, Android 11, Android Studio 4

Part 1: Visual Feedback: Dialogs, Snackbars & Toasts

5. Use Custom Dialogs

Lesson Complete

Play Next Lesson
Save for later
About this episode
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 4. Use Alert Dialogs Next episode: 6. Use Progress Indicators

This video was last updated on Mar 16 2021

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

Sometimes, you’ll want to show a more unique or complex dialog to your users. By creating a custom dialog, you can define your own layout to display in the main content area of the dialog.

activity?.let {
 val inflater = it.layoutInflater
     .setView(inflater.inflate(R.layout.dialog_fruit, null))
     .setPositiveButton(R.string.dialog_fruit_close) { _, _ ->
} ?: throw IllegalStateException("Activity cannot be null")
fun onDialogButtonClicked()

Showing the Custom Dialog $[==]

Now, you need to show the dialog. Go back to MainActivity.kt and find the card with ID card_mystery. This card already has a click listener assigned that calls loadSurpriseDialog(), which has not yet been implemented.

CustomFruitDialog().apply {
 listener = object : CustomFruitDialog.Listener {
   override fun onDialogButtonClicked() {
}.show(supportFragmentManager, TAG_FRUIT_DIALOG)