UX4G Logo
Components

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, and Slot states.
  • Title & Supporting Description: Emphasized bold heading with an optional secondary subtitle describing the status or error details.
  • Adaptive Layout Modes: Supports Full layout (one-line format for tablet/desktop) and Stacked layout (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: Ux4gToastHost and Ux4gToastHostState for coordinated top or bottom animated slide and fade overlays with auto-close timers.

Import from:

import com.ux4g.designsystemv1.components.toast.*

Interactive Preview

Ux4gToastJetpack Compose
UX4G Toast Category Messages Preview

Complete Kotlin Implementation

1. Static Inline Toast Messages

Use Ux4gToast directly inside form layouts or dialogs when you need persistent feedback banners:

StaticToastShowcase.kt
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:

ApplicationSubmissionScreen.kt
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)

PropTypeDescriptionDefault
category *Ux4gToastCategorySemantic tone determining icon, background tint, and action colors (Info, Success, Warning, Error, Slot).—
title *StringPrimary bold notification heading text.—
modifierModifierCompose layout modifier applied to the toast card container.Modifier
subtitleString?Optional secondary description text providing supporting context.null
actionTextString?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
showCloseButtonBooleanWhether to render the trailing close (X) dismiss button.true
layoutUx4gToastLayout?Layout structure: Full (single-line horizontal) or Stacked (multi-line indented for mobile).Auto-detected

2. Ux4gToastHost Composable (Floating Container)

PropTypeDescriptionDefault
hostState *Ux4gToastHostStateState object controlling current active toast display, animations, and dismissal.—
modifierModifierCompose modifier applied to the toast host container.Modifier
isBottomBooleanPosition 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.

ParameterTypeDescriptionDefault
category *Ux4gToastCategorySemantic tone determining theme styling (Info, Success, Warning, Error, Slot).Ux4gToastCategory.Info
title *StringPrimary bold notification heading text.—
subtitleString?Optional supporting description text.null
actionTextString?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
durationMillisLongAutomatic dismissal countdown duration in milliseconds.4000L

4. Ux4gToastData Data Model

Immutable data model representing the active toast payload managed inside Ux4gToastHostState.

FieldTypeDescriptionDefault
categoryUx4gToastCategorySemantic category tone for the toast instance.Ux4gToastCategory.Info
titleStringBold notification title headline.""
subtitleString?Supporting text message.null
actionTextString?Optional right-side CTA button text.null
onActionClick(() -> Unit)?Action button click callback.null
onCloseClick(() -> Unit)?Close button dismiss callback.null
durationMillisLongToast duration on screen.4000L

5. Ux4gToastCategory Reference Guide

CategoryBackground ColorIcon TintStandard IconPurpose
InfoUx4gColors.cyan50Ux4gColors.cyan500Ux4gIcons.info_circleInformational announcements, sync status, and generic notices
SuccessUx4gColors.green50Ux4gColors.green500Ux4gIcons.success_circleConfirmation of completed applications, uploads, and saved data
WarningUx4gColors.gold50Ux4gColors.gold600Ux4gIcons.warningSession expiration warnings, pending documents, or soft limits
ErrorUx4gColors.red50Ux4gColors.red600Ux4gIcons.errorFailed network requests, authorization errors, or upload failures
SlotUx4gColors.purple50Ux4gColors.purple500Ux4gIcons.SettingsCustom slot or administrative system notification

On this page