संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
स्नैकबार कॉम्पोनेंट, स्क्रीन पर सबसे नीचे दिखने वाली एक छोटी सूचना के तौर पर काम करता है. यह उपयोगकर्ता अनुभव में रुकावट डाले बिना, किसी ऑपरेशन या कार्रवाई के बारे में सुझाव/राय देता है या शिकायत करता है. स्नैकबार कुछ सेकंड बाद गायब हो जाते हैं. उपयोगकर्ता, किसी कार्रवाई के ज़रिए भी सूचनाओं को खारिज कर सकता है. जैसे, किसी बटन पर टैप करना.
यहां इस्तेमाल के तीन उदाहरण दिए गए हैं. इनमें स्नैकबार का इस्तेमाल किया जा सकता है:
कार्रवाई की पुष्टि करना: जब कोई उपयोगकर्ता किसी ईमेल या मैसेज को मिटाता है, तो कार्रवाई की पुष्टि करने के लिए एक स्नैकबार दिखता है. इसमें "पहले जैसा करें" विकल्प भी होता है.
नेटवर्क की स्थिति: जब ऐप्लिकेशन का इंटरनेट कनेक्शन बंद हो जाता है, तो एक स्नैकबार
पॉप अप होता है. इससे पता चलता है कि ऐप्लिकेशन अब ऑफ़लाइन है.
डेटा सबमिट करना: फ़ॉर्म सबमिट करने या सेटिंग अपडेट करने के बाद, स्नैकबार में यह सूचना दिखती है कि बदलाव सेव हो गया है.
पहली इमेज. स्नैकबार के उदाहरण.
बुनियादी उदाहरण
स्नैकबार लागू करने के लिए, सबसे पहले SnackbarHost बनाएं. इसमें SnackbarHostState प्रॉपर्टी शामिल होती है. SnackbarHostStateshowSnackbar() फ़ंक्शन को ऐक्सेस करने की सुविधा देता है. इसका इस्तेमाल स्नैकबार दिखाने के लिए किया जा सकता है.
निलंबित करने वाले इस फ़ंक्शन के लिए, CoroutineScope की ज़रूरत होती है. जैसे, rememberCoroutineScope का इस्तेमाल करना. इसे यूज़र इंटरफ़ेस (यूआई) इवेंट के जवाब में कॉल किया जा सकता है, ताकि Scaffold में Snackbar दिखाया जा सके.
आपके पास कोई वैकल्पिक कार्रवाई देने और Snackbar की अवधि में बदलाव करने का विकल्प होता है.
snackbarHostState.showSnackbar() फ़ंक्शन, actionLabel और duration पैरामीटर स्वीकार करता है. साथ ही, SnackbarResult दिखाता है.
valscope=rememberCoroutineScope()valsnackbarHostState=remember{SnackbarHostState()}Scaffold(snackbarHost={SnackbarHost(hostState=snackbarHostState)},floatingActionButton={ExtendedFloatingActionButton(text={Text("Show snackbar")},icon={Icon(Icons.Filled.Image,contentDescription="")},onClick={scope.launch{valresult=snackbarHostState.showSnackbar(message="Snackbar",actionLabel="Action",// Defaults to SnackbarDuration.Shortduration=SnackbarDuration.Indefinite)when(result){SnackbarResult.ActionPerformed->{/* Handle snackbar action performed */}SnackbarResult.Dismissed->{/* Handle snackbar dismissed */}}}})}){contentPadding->
// Screen content}
actionLabel = "Action": इससे ऐक्शन बटन का टेक्स्ट सेट किया जाता है.
withDismissAction = true: यह स्नैकबार में क्रॉस का निशान दिखाता है. स्नैकबार को खारिज करने के लिए, इस पर टैप करें.
duration = SnackbarDuration.Indefinite: यह कुकी, स्नैकबार को तब तक दिखाती है, जब तक उपयोगकर्ता या प्रोग्राम उसे खारिज नहीं कर देता.
SnackbarResult.ActionPerformed: इससे पता चलता है कि उपयोगकर्ता ने स्नैकबार के ऐक्शन बटन पर क्लिक किया है.
SnackbarResult.Dismissed: इससे पता चलता है कि उपयोगकर्ता ने ऐक्शन बटन पर क्लिक किए बिना स्नैकबार को खारिज कर दिया है.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-08-28 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-08-28 (UTC) को अपडेट किया गया."],[],[],null,["The [snackbar component](https://m3.material.io/components/snackbar/overview) serves as a brief notification that appears at the\nbottom of the screen. It provides feedback about an operation or action without\ninterrupting the user experience. Snackbars disappear after a few seconds. The\nuser can also dismiss them with an action, such as tapping a button.\n\nConsider these three use cases where you might use a snackbar:\n\n- **Action Confirmation:** After a user deletes an email or message, a snackbar appears to confirm the action and offer an \"Undo\" option.\n- **Network Status:** When the app loses its internet connection, a snackbar pops up to note that it is now offline.\n- **Data Submission:** Upon successfully submitting a form or updating settings, a snackbar notes that the change has saved successfully.\n\n**Figure 1.** Snackbar examples.\n\nBasic example\n\nTo implement a snackbar, you first create [`SnackbarHost`](/reference/kotlin/androidx/compose/material3/package-summary#SnackbarHost(androidx.compose.material3.SnackbarHostState,androidx.compose.ui.Modifier,kotlin.Function1)), which includes a\n[`SnackbarHostState`](/reference/kotlin/androidx/compose/material3/SnackbarHostState) property. `SnackbarHostState` provides access to the\n[`showSnackbar()`](/reference/kotlin/androidx/compose/material3/SnackbarHostState#showsnackbar) function which you can use to display your snackbar.\n\nThis suspending function requires a `CoroutineScope` such as with using\n[`rememberCoroutineScope`](/reference/kotlin/androidx/compose/runtime/package-summary#remembercoroutinescope) --- and can be called in response to UI events to\nshow a [`Snackbar`](/reference/kotlin/androidx/compose/material3/package-summary#snackbar) within `Scaffold`.\n\n\n```kotlin\nval scope = rememberCoroutineScope()\nval snackbarHostState = remember { SnackbarHostState() }\nScaffold(\n snackbarHost = {\n SnackbarHost(hostState = snackbarHostState)\n },\n floatingActionButton = {\n ExtendedFloatingActionButton(\n text = { Text(\"Show snackbar\") },\n icon = { Icon(Icons.Filled.Image, contentDescription = \"\") },\n onClick = {\n scope.launch {\n snackbarHostState.showSnackbar(\"Snackbar\")\n }\n }\n )\n }\n) { contentPadding -\u003e\n // Screen content\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/compose/snippets/src/main/java/com/example/compose/snippets/layouts/MaterialLayoutSnippets.kt#L218-L240\n```\n\n\u003cbr /\u003e\n\nSnackbar with action\n\nYou can provide an optional action and adjust the duration of the `Snackbar`.\nThe `snackbarHostState.showSnackbar()` function accepts additional `actionLabel`\nand `duration` parameters, and returns a [`SnackbarResult`](/reference/kotlin/androidx/compose/material3/SnackbarResult).\n\n\n```kotlin\nval scope = rememberCoroutineScope()\nval snackbarHostState = remember { SnackbarHostState() }\nScaffold(\n snackbarHost = {\n SnackbarHost(hostState = snackbarHostState)\n },\n floatingActionButton = {\n ExtendedFloatingActionButton(\n text = { Text(\"Show snackbar\") },\n icon = { Icon(Icons.Filled.Image, contentDescription = \"\") },\n onClick = {\n scope.launch {\n val result = snackbarHostState\n .showSnackbar(\n message = \"Snackbar\",\n actionLabel = \"Action\",\n // Defaults to SnackbarDuration.Short\n duration = SnackbarDuration.Indefinite\n )\n when (result) {\n SnackbarResult.ActionPerformed -\u003e {\n /* Handle snackbar action performed */\n }\n SnackbarResult.Dismissed -\u003e {\n /* Handle snackbar dismissed */\n }\n }\n }\n }\n )\n }\n) { contentPadding -\u003e\n // Screen content\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/compose/snippets/src/main/java/com/example/compose/snippets/layouts/MaterialLayoutSnippets.kt#L247-L283\n```\n\n\u003cbr /\u003e\n\nYou can provide a custom `Snackbar` with the `snackbarHost` parameter. See the\n[`SnackbarHost` API reference docs](/reference/kotlin/androidx/compose/material/package-summary#snackbarhost) for more information.\n\nKey points\n\n- `actionLabel = \"Action\"`: Sets the action button text.\n- `withDismissAction = true`: Provides a cross in the snackbar. Tap it to dismiss the snackbar.\n- `duration = SnackbarDuration.Indefinite`: Keeps the snackbar displayed until the user or program dismisses it.\n- `SnackbarResult.ActionPerformed`: Signifies that the user clicked the snackbar's action button.\n- `SnackbarResult.Dismissed`: Signifies that the user dismissed the snackbar without clicking the action button."]]