Snackbar
Brief message confirming something that already happened, shown at the bottom of the screen without taking focus. SnackbarHost supplies the announcement, the dismiss action, and the time extension a user can ask for; a Snackbar drawn outside it gets none of them.
Selection
The criteria an agent checks before retrieving this component.
Use when
- Use when a brief message confirms that something the user did has happened (e.g., "Draft saved", "Link copied").
- Use when the message needs no response and the user may ignore it.
Try a different component when
- Do not use when the message offers an action the user may want to take (use
snackbar.action). - Do not use when the user must respond before continuing (use
dialog.alert). - Do not use when the message reports an error in a field the user is filling in. Report it on the field (use
text-field.basic).
Must Haves
Non-negotiable structure. Every generated instance must satisfy these rules.
- The message is announced without moving focus, can be dismissed without a gesture, and stays on screen at least as long as the user's accessibility timeout asks. Material's
SnackbarHostis the reference implementation of that contract, through a polite live region, adismissaccessibility action, and a duration passed through the system's recommended timeout (global.native-first). - Show the message through
SnackbarHostState.showSnackbar, with theSnackbarHostplaced in the screen'sScaffold. - Leave focus where it is when the message appears (
global.focus-management). - Keep the message to one short sentence that makes sense without the screen around it (e.g., "Draft saved", not "Done").
- Use
SnackbarDuration.ShortorSnackbarDuration.Long. Both are lengthened for a user who has set a longer accessibility timeout.
Donts
Avoid these accessibility and UX barriers.
- Do not render a
Snackbardirectly, such as insideAnimatedVisibilitywith adelay()that hides it. It is then not announced, has no dismiss action, and ignores the user's timeout setting. - Do not move focus to the message. It interrupts what the user was doing for something that needs nothing from them.
- Do not use
android.widget.Toastin place of a snackbar. It is a different platform API from Material's, outside the screen's own content, and it cannot carry an action. - Do not use a snackbar for anything the user has to see to continue. It leaves on its own.
- Do not show a message for each of a burst of actions.
showSnackbarqueues them, each waiting for the one before it to leave, so the user keeps hearing confirmations for things they finished long ago.
Customizable
Alternatives and options that give the AI agent some room to move.
- The message may sit in the default position at the bottom of the
Scaffold, or in aSnackbarHostplaced elsewhere, provided it is still aSnackbarHost. showSnackbar(withDismissAction = true)may add a visible close control for a long message.Snackbarcolors and shape may follow the brand through the host'ssnackbarslot, which keeps the host's semantics.
Golden Pattern
The tested reference implementation. Agents start from this shape and adapt to the developer’s codebase and context.
@Composable
fun SnackbarExamples() {
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
snackbarHost = { SnackbarHost(hostState = snackbarHostState) }
) { padding ->
Column(Modifier.padding(padding)) {
Button(onClick = {
/* save */
scope.launch {
snackbarHostState.showSnackbar(
message = "Draft saved",
duration = SnackbarDuration.Short
)
}
}) {
Text("Save draft")
}
}
}
}