Visual Feedback: Dialogs, Snackbars & Toasts

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

Part 1: Visual Feedback: Dialogs, Snackbars & Toasts

02. Use Dialogs & MaterialAlertDialogBuilder

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 01. Work with Touch States Next episode: 03. Use Simple & Confirmation Dialogs

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 02. Use Dialogs & MaterialAlertDialogBuilder

Dialogs are small, versatile windows overlaid above the main content on the screen. They can be useful for getting the required input from users or making the user aware of important events. However, they block the rest of the content and can disrupt or take over the attention of the user. Therefore, dialogs should be used sparingly and intentionally. In some cases, it might be better to consider redesigning to use overflow menus or a Snackbar, which you’ll learn how to do shortly.

Various types of dialogs cater to different use cases. The Material Components library provides support for three main types:

Simple Dialog: Displays a title and list of items. This dialog doesn’t have any buttons. Instead, the action is triggered when an item is selected.

Confirmation Dialog: Similar in design to the simple dialog with the addition up to two buttons: positive and neutral. This type of dialog has the option of multiple item selection and does not trigger an action until the user presses the positive button.

Alert Dialog: Has optional title, message and up to three buttons: positive, negative and neutral. This dialog is used when the app requires the user to make a decision or confirm that they have read important information.

The MaterialAlertDialogBuilder provides several functions for setting up a dialog. The builder creates an Android AlertDialog using any defined color or shape in the current app theme, as long as the app uses a Material theme. Use this builder to create any of the dialogs defined in the Material Components library.

To use the builder, you need to import it first. Add the following import statement to the top of MainActivity.kt:

import com.google.android.material.dialog.MaterialAlertDialogBuilder