با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
یک نان تست بازخورد ساده ای در مورد یک عملیات در یک بازشو کوچک ارائه می دهد. فقط مقدار فضای مورد نیاز برای پیام را پر می کند و فعالیت فعلی قابل مشاهده و تعاملی باقی می ماند. نان تست ها به طور خودکار پس از یک بازه زمانی ناپدید می شوند.
به عنوان مثال، کلیک کردن بر روی ارسال در یک ایمیل، یک نان تست "ارسال پیام..." را فعال می کند، همانطور که در تصویر زیر از صفحه نشان داده شده است:
اگر برنامه شما اندروید 12 (سطح API 31) یا بالاتر را هدف قرار می دهد، تست آن به دو خط متن محدود می شود و نماد برنامه را در کنار متن نشان می دهد. توجه داشته باشید که طول خط این متن بسته به اندازه صفحه متفاوت است، بنابراین خوب است متن را تا حد امکان کوتاه کنید.
جایگزین های استفاده از نان تست
اگر برنامه شما در پیش زمینه است، به جای استفاده از نان تست، از اسنک بار استفاده کنید. اسنکبارها شامل گزینههای کاربردی برای کاربر هستند که میتوانند تجربه بهتری از اپلیکیشن را ارائه دهند.
اگر برنامه شما در پسزمینه است و میخواهید کاربران اقداماتی انجام دهند، به جای آن از یک اعلان استفاده کنید.
نمونه سازی یک شی نان تست
از متد makeText() استفاده کنید که پارامترهای زیر را می گیرد:
همانطور که در قطعه کد زیر نشان داده شده است، میتوانید روشهای خود را زنجیرهای کنید تا از نگه داشتن شی Toast اجتناب کنید:
کاتلین
Toast.makeText(context,text,duration).show()
جاوا
Toast.makeText(context,text,duration).show();
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Toasts overview\n\nA toast provides simple feedback about an operation in a small popup. It only\nfills the amount of space required for the message and the current activity\nremains visible and interactive. Toasts automatically disappear after a timeout.\n\nFor example, clicking **Send** on an email triggers a \"Sending message...\"\ntoast, as shown in the following screen capture:\n\nIf your app targets Android 12 (API level 31) or higher, its toast is limited to\ntwo lines of text and shows the application icon next to the text. Be aware that\nthe line length of this text varies by screen size, so it's good to make the\ntext as short as possible.\n\nAlternatives to using toasts\n----------------------------\n\nIf your app is in the foreground, consider using a\n[snackbar](https://material.io/components/snackbars) instead of using a toast.\nSnackbars include user-actionable options, which can provide a better app\nexperience.\n\nIf your app is in the background, and you want users to take some action, use\na [notification](/develop/ui/views/notifications)\ninstead.\n\nInstantiate a Toast object\n--------------------------\n\nUse the\n[`makeText()`](/reference/android/widget/Toast#makeText(android.content.Context,%20int,%20int))\nmethod, which takes the following parameters:\n\n1. The activity [`Context`](/reference/android/content/Context).\n2. The text that should appear to the user.\n3. The duration that the toast should remain on the screen.\n\nThe `makeText()` method returns a properly initialized `Toast` object.\n\nShow the toast\n--------------\n\nTo display the toast, call the\n[`show()`](/reference/android/widget/Toast#show()) method, as demonstrated in\nthe following example: \n\n### Kotlin\n\n```kotlin\nval text = \"Hello toast!\"\nval duration = Toast.LENGTH_SHORT\n\nval toast = Toast.makeText(this, text, duration) // in Activity\ntoast.show()\n```\n\n### Java\n\n```java\nCharSequence text = \"Hello toast!\";\nint duration = Toast.LENGTH_SHORT;\n\nToast toast = Toast.makeText(this /* MyActivity */, text, duration);\ntoast.show();\n```\n\nChain your toast method calls\n-----------------------------\n\nYou can chain your methods to avoid holding on to the `Toast` object, as shown\nin the following code snippet: \n\n### Kotlin\n\n```kotlin\nToast.makeText(context, text, duration).show()\n```\n\n### Java\n\n```java\nToast.makeText(context, text, duration).show();\n```"]]