Toast & Snackbars
Transient feedback messages with category icons, titles, subtitles, action buttons, and animated top/bottom toast host positioning
The UX4G Toast and Snackbar component displays non-intrusive, transient feedback messages to inform citizens about application submissions, system status updates, validation warnings, and background process results.
Key Capabilities
- Semantic Feedback Categories: Pre-styled visual indicators for
Info,Success,Warning,Error, andSlotstates. - Title & Supporting Description: Emphasized bold heading with an optional secondary subtitle describing the status or error details.
- Adaptive Layout Modes: Supports
Fulllayout (one-line format for tablet/desktop) andStackedlayout (multi-line indented format for mobile devices). - Interactive Action Buttons & Dismiss: Integrated call-to-action link button (
actionText,onActionClick) and optional dismiss close button (onCloseClick). - Animated Toast Host:
Ux4gToastHostandUx4gToastHostStatefor coordinated top or bottom animated slide and fade overlays with auto-close timers.
Import from:
import com.ux4g.designsystemv1.components.toast.*Interactive Preview

Complete Kotlin Implementation
1. Static Inline Toast Messages
Use Ux4gToast directly inside form layouts or dialogs when you need persistent feedback banners:
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.toast.*
@Composable
fun FormFeedbackSection() {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
// Successful Document Upload Toast
Ux4gToast(
category = Ux4gToastCategory.Success,
title = "Aadhaar Card Uploaded",
subtitle = "File verified successfully. Size: 1.4 MB",
actionText = "Preview",
onActionClick = { /* Open preview */ },
onCloseClick = { /* Dismiss */ }
)
// Connectivity Warning Toast
Ux4gToast(
category = Ux4gToastCategory.Warning,
title = "Slow Connection Detected",
subtitle = "Uploads may take longer than usual."
)
}
}2. Floating Animated Toast Host in Scaffold
Use Ux4gToastHost combined with Ux4gToastHostState to trigger floating notifications anywhere in your application:
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.buttons.Ux4gButton
import com.ux4g.designsystemv1.components.toast.*
import kotlinx.coroutines.launch
@Composable
fun ApplicationSubmissionScreen() {
val coroutineScope = rememberCoroutineScope()
val toastHostState = remember { Ux4gToastHostState() }
Scaffold(
topBar = {
// Animated Top Toast Host Overlay
Ux4gToastHost(
hostState = toastHostState,
isBottom = false
)
}
) { paddingValues ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Ux4gButton(
text = "Submit Certificate Request",
onClick = {
coroutineScope.launch {
toastHostState.showToast(
category = Ux4gToastCategory.Success,
title = "Application Submitted Successfully",
subtitle = "Reference ID: APP-2026-9821 has been generated.",
actionText = "Track",
onActionClick = { /* Navigate to status tracking */ },
durationMillis = 4000L
)
}
}
)
}
}
}Parameters & API Reference
1. Ux4gToast Composable (Card Component)
| Prop | Type | Description | Default |
|---|---|---|---|
category * | Ux4gToastCategory | Semantic tone determining icon, background tint, and action colors (Info, Success, Warning, Error, Slot). | — |
title * | String | Primary bold notification heading text. | — |
modifier | Modifier | Compose layout modifier applied to the toast card container. | Modifier |
subtitle | String? | Optional secondary description text providing supporting context. | null |
actionText | String? | Optional text label for the right-aligned action trigger button. | null |
onActionClick | (() -> Unit)? | Callback invoked when the citizen taps the action text. | null |
onCloseClick | (() -> Unit)? | Callback triggered when the citizen taps the close (X) icon button. | null |
showCloseButton | Boolean | Whether to render the trailing close (X) dismiss button. | true |
layout | Ux4gToastLayout? | Layout structure: Full (single-line horizontal) or Stacked (multi-line indented for mobile). | Auto-detected |
2. Ux4gToastHost Composable (Floating Container)
| Prop | Type | Description | Default |
|---|---|---|---|
hostState * | Ux4gToastHostState | State object controlling current active toast display, animations, and dismissal. | — |
modifier | Modifier | Compose modifier applied to the toast host container. | Modifier |
isBottom | Boolean | Position flag: When true, slides up from bottom; when false, slides down from top. | false |
3. Ux4gToastHostState.showToast(...) Method
Method called on toastHostState inside a coroutine scope to display a temporary notification.
| Parameter | Type | Description | Default |
|---|---|---|---|
category * | Ux4gToastCategory | Semantic tone determining theme styling (Info, Success, Warning, Error, Slot). | Ux4gToastCategory.Info |
title * | String | Primary bold notification heading text. | — |
subtitle | String? | Optional supporting description text. | null |
actionText | String? | Text label for the trailing action trigger button (e.g. "View", "Track"). | null |
onActionClick | (() -> Unit)? | Callback invoked when the citizen taps the action text button. | null |
durationMillis | Long | Automatic dismissal countdown duration in milliseconds. | 4000L |
4. Ux4gToastData Data Model
Immutable data model representing the active toast payload managed inside Ux4gToastHostState.
| Field | Type | Description | Default |
|---|---|---|---|
category | Ux4gToastCategory | Semantic category tone for the toast instance. | Ux4gToastCategory.Info |
title | String | Bold notification title headline. | "" |
subtitle | String? | Supporting text message. | null |
actionText | String? | Optional right-side CTA button text. | null |
onActionClick | (() -> Unit)? | Action button click callback. | null |
onCloseClick | (() -> Unit)? | Close button dismiss callback. | null |
durationMillis | Long | Toast duration on screen. | 4000L |
5. Ux4gToastCategory Reference Guide
| Category | Background Color | Icon Tint | Standard Icon | Purpose |
|---|---|---|---|---|
Info | Ux4gColors.cyan50 | Ux4gColors.cyan500 | Ux4gIcons.info_circle | Informational announcements, sync status, and generic notices |
Success | Ux4gColors.green50 | Ux4gColors.green500 | Ux4gIcons.success_circle | Confirmation of completed applications, uploads, and saved data |
Warning | Ux4gColors.gold50 | Ux4gColors.gold600 | Ux4gIcons.warning | Session expiration warnings, pending documents, or soft limits |
Error | Ux4gColors.red50 | Ux4gColors.red600 | Ux4gIcons.error | Failed network requests, authorization errors, or upload failures |
Slot | Ux4gColors.purple50 | Ux4gColors.purple500 | Ux4gIcons.Settings | Custom slot or administrative system notification |
Time Picker
Interactive time selection trigger field and scroll-wheel dialog modal supporting 12-hour AM/PM formats, custom minute intervals, and validation states
Toggle Switch
Accessible binary on/off switches with smooth animations, customizable sizes, label positions, required markers, and trailing icons