Android Dialog Icons are optional visual elements placed at the top of a pop-up dialog box to provide immediate context about the notification, warning, or decision a user needs to make. In modern Material Design 3 (M3) guidelines, dialog icons serve as a “hero” visual anchor to support the headline and help the user quickly understand the purpose of the interruption. Implementation in Modern Android (Jetpack Compose)
In modern development, dialogs are built using Jetpack Compose UI Toolkit. The AlertDialog component includes a dedicated slot for the icon.
AlertDialog( onDismissRequest = { /Handle dismiss */ }, confirmButton = { TextButton(onClick = { … }) { Text(“Confirm”) } }, dismissButton = { TextButton(onClick = { … }) { Text(“Dismiss”) } }, icon = { Icon(Icons.Default.Warning, contentDescription = “Warning Icon”) }, title = { Text(text = “Delete Account?”) }, text = { Text(“This action cannot be undone.”) } ) Use code with caution. Implementation in Legacy XML (View System)
In legacy Android applications using XML layouts, developers use the AlertDialog.Builder class. Icons can be set programmatically in two ways:
Using Resource ID: builder.setIcon(R.drawable.ic_dialog_warning)
Using a Drawable object: builder.setIcon(ContextCompat.getDrawable(context, R.drawable.your_icon))
Android historically provided built-in system dialog icons like android.R.drawable.ic_dialog_info, ic_dialog_alert, and ic_dialog_email, though modern apps typically import custom vector assets to match their brand. Design Best Practices (Material 3) How to show appropriate icon on dialog box – android
Leave a Reply