با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
جزء Chip یک عنصر رابط کاربری فشرده و تعاملی است. این موجودات پیچیده مانند یک مخاطب یا برچسب، اغلب با یک نماد و برچسب را نشان می دهد. می تواند قابل بررسی، رد کردن یا کلیک کردن باشد.
چهار نوع تراشه و محل استفاده از آنها به شرح زیر است:
Assist : کاربر را در طول یک کار راهنمایی می کند. اغلب به عنوان یک عنصر رابط کاربری موقت در پاسخ به ورودی کاربر ظاهر می شود.
فیلتر : به کاربران امکان می دهد محتوا را از مجموعه ای از گزینه ها اصلاح کنند. آنها را می توان انتخاب کرد یا از حالت انتخاب خارج کرد، و ممکن است هنگام انتخاب یک نماد علامت چک داشته باشند.
ورودی : اطلاعات ارائه شده توسط کاربر، مانند انتخاب های موجود در یک منو را نشان می دهد. آنها می توانند شامل یک نماد و متن باشند و یک X برای حذف ارائه دهند.
پیشنهاد : توصیه هایی را بر اساس فعالیت یا ورودی اخیر به کاربر ارائه می دهد. معمولاً در زیر یک فیلد ورودی ظاهر میشود تا اقدامات کاربر را درخواست کند.
شکل 1. چهار جزء تراشه.
سطح API
چهار نوع ترکیب وجود دارد که با چهار نوع تراشه مطابقت دارد. بخشهای بعدی این ترکیبپذیرها و تفاوتهای آنها را با جزئیات شرح میدهند. با این حال، آنها پارامترهای زیر را به اشتراک می گذارند:
label : رشته ای که روی تراشه ظاهر می شود.
icon : نمادی که در ابتدای تراشه نمایش داده می شود. برخی از composable های خاص دارای پارامتر leadingIcon و trailingIcon جداگانه هستند.
onClick : لامبدای که تراشه وقتی کاربر آن را فشار میدهد آن را صدا میزند.
تراشه کمکی
AssistChip composable یک راه ساده برای ایجاد یک تراشه کمکی ارائه می دهد که کاربر را به یک جهت خاص هدایت می کند. یکی از ویژگی های متمایز، پارامتر leadingIcon آن است که به شما امکان می دهد یک نماد را در سمت چپ تراشه نمایش دهید. مثال زیر نشان می دهد که چگونه می توانید آن را پیاده سازی کنید:
قابلیت Composable FilterChip از شما میخواهد ردیابی کنید که آیا تراشه انتخاب شده است یا خیر. مثال زیر نشان میدهد که چگونه میتوانید تنها زمانی که کاربر تراشه را انتخاب کرده باشد، یک نماد علامتدار اصلی را نشان دهید:
این پیاده سازی در صورت عدم انتخاب به صورت زیر ظاهر می شود:
شکل 3. تراشه فیلتر انتخاب نشده.
و هنگام انتخاب به صورت زیر ظاهر می شود:
شکل 4. تراشه فیلتر انتخاب شده.
تراشه ورودی
شما می توانید از InputChip composable برای ایجاد تراشه هایی که از تعامل کاربر ایجاد می شود استفاده کنید. به عنوان مثال، در یک سرویس گیرنده ایمیل، زمانی که کاربر در حال نوشتن ایمیل است، یک تراشه ورودی ممکن است نمایانگر مخاطبی باشد که کاربر به فیلد "To:" اضافه کرده است.
پیاده سازی زیر یک تراشه ورودی را نشان می دهد که در حال حاضر در یک حالت انتخاب شده است. هنگامی که کاربر تراشه را فشار می دهد، آن را حذف می کند.
ترکیبپذیر SuggestionChip اساسیترین ترکیبپذیر فهرستشده در این صفحه است، هم در تعریف API و هم در موارد استفاده رایج آن. تراشههای پیشنهاد نکاتی را ارائه میدهند که به صورت پویا تولید میشوند. به عنوان مثال، در یک برنامه چت هوش مصنوعی، ممکن است از تراشههای پیشنهاد برای ارائه پاسخهای احتمالی به جدیدترین پیام استفاده کنید.
همه نمونههای موجود در این سند از ترکیبهای پایه استفاده میکنند که ظاهری مسطح دارند. اگر تراشه ای می خواهید که ظاهری برجسته داشته باشد، از یکی از سه ترکیب زیر استفاده کنید:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-28 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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 بهوقت ساعت هماهنگ جهانی."],[],[],null,["The `Chip` component is a compact, interactive UI element. It represents complex\nentities like a contact or tag, often with an icon and label. It can be\ncheckable, dismissible, or clickable.\n\nThe four types of chips and where you might use them are as follows:\n\n- **Assist**: Guides the user during a task. Often appears as a temporary UI element in response to user input.\n- **Filter**: Allows users to refine content from a set of options. They can be selected or deselected, and may include a checkmark icon when selected.\n- **Input** : Represents user-provided information, such as selections in a menu. They can contain an icon and text, and provide an **X** for removal.\n- **Suggestion**: Provides recommendations to the user based on their recent activity or input. Typically appear beneath an input field to prompt user actions.\n\n**Figure 1.** The four chip components.\n\nAPI surface\n\nThere are four composables that correspond to the four types of chips. The\nfollowing sections outline these composables and their differences in detail.\nHowever, they share the following parameters:\n\n- **`label`**: The string that appears on the chip.\n- **`icon`** : The icon displayed at the start of the chip. Some of the specific composables have a separate `leadingIcon` and `trailingIcon` parameter.\n- **`onClick`**: The lambda that the chip calls when the user presses it.\n\nAssist chip\n\nThe [`AssistChip`](/reference/kotlin/androidx/compose/material3/package-summary#AssistChip(kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.graphics.Shape,androidx.compose.material3.ChipColors,androidx.compose.material3.ChipElevation,androidx.compose.material3.ChipBorder,androidx.compose.foundation.interaction.MutableInteractionSource)) composable provides a straightforward way to create an\nassist chip that nudges the user in a particular direction. One distinguishing\nfeature is its `leadingIcon` parameter that lets you display an icon on the left\nside of the chip. The following example demonstrates how you can implement it:\n\n\n```kotlin\n@Composable\nfun AssistChipExample() {\n AssistChip(\n onClick = { Log.d(\"Assist chip\", \"hello world\") },\n label = { Text(\"Assist chip\") },\n leadingIcon = {\n Icon(\n Icons.Filled.Settings,\n contentDescription = \"Localized description\",\n Modifier.size(AssistChipDefaults.IconSize)\n )\n }\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/Chip.kt#L72-L85\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows.\n**Figure 2.** Assist chip.\n\nFilter chip\n\nThe [`FilterChip`](/reference/kotlin/androidx/compose/material3/package-summary#FilterChip(kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.graphics.Shape,androidx.compose.material3.SelectableChipColors,androidx.compose.material3.SelectableChipElevation,androidx.compose.material3.SelectableChipBorder,androidx.compose.foundation.interaction.MutableInteractionSource)) composable requires you to track whether or not the chip\nis selected. The following example demonstrates how you can show a leading\nchecked icon only when the user has selected the chip:\n\n\n```kotlin\n@Composable\nfun FilterChipExample() {\n var selected by remember { mutableStateOf(false) }\n\n FilterChip(\n onClick = { selected = !selected },\n label = {\n Text(\"Filter chip\")\n },\n selected = selected,\n leadingIcon = if (selected) {\n {\n Icon(\n imageVector = Icons.Filled.Done,\n contentDescription = \"Done icon\",\n modifier = Modifier.size(FilterChipDefaults.IconSize)\n )\n }\n } else {\n null\n },\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/Chip.kt#L90-L112\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows when unselected:\n**Figure 3.** Unselected filter chip.\n\nAnd appears as follows when selected:\n**Figure 4.** Selected filter chip.\n\nInput chip\n\nYou can use the [`InputChip`](/reference/kotlin/androidx/compose/material3/package-summary#InputChip(kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,kotlin.Function0,kotlin.Function0,androidx.compose.ui.graphics.Shape,androidx.compose.material3.SelectableChipColors,androidx.compose.material3.SelectableChipElevation,androidx.compose.material3.SelectableChipBorder,androidx.compose.foundation.interaction.MutableInteractionSource)) composable to create chips that result from\nuser interaction. For example, in an email client, when the user is writing an\nemail, an input chip might represent a contact the user has added to the \"To:\"\nfield.\n\nThe following implementation demonstrates an input chip that is already in a\nselected state. The user dismisses the chip when they press it.\n| **Note:** Consider how you might use a chip like this in the preceding email use case, with a name passed in for the `label` parameter, and a function that performs the necessary network calls for `onDismiss`.\n\n\n```kotlin\n@Composable\nfun InputChipExample(\n text: String,\n onDismiss: () -\u003e Unit,\n) {\n var enabled by remember { mutableStateOf(true) }\n if (!enabled) return\n\n InputChip(\n onClick = {\n onDismiss()\n enabled = !enabled\n },\n label = { Text(text) },\n selected = enabled,\n avatar = {\n Icon(\n Icons.Filled.Person,\n contentDescription = \"Localized description\",\n Modifier.size(InputChipDefaults.AvatarSize)\n )\n },\n trailingIcon = {\n Icon(\n Icons.Default.Close,\n contentDescription = \"Localized description\",\n Modifier.size(InputChipDefaults.AvatarSize)\n )\n },\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/Chip.kt#L118-L148\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows.\n**Figure 5.** Input chip.\n\nSuggestion chip\n\nThe [`SuggestionChip`](/reference/kotlin/androidx/compose/material3/package-summary#SuggestionChip(kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,androidx.compose.ui.graphics.Shape,androidx.compose.material3.ChipColors,androidx.compose.material3.ChipElevation,androidx.compose.material3.ChipBorder,androidx.compose.foundation.interaction.MutableInteractionSource)) composable is the most basic of the composables listed\non this page, both in its API definition and its common use cases. Suggestion\nchips present dynamically generated hints. For example, in an AI chat app, you\nmight use suggestion chips to present possible responses to the most recent\nmessage.\n\nConsider this implementation of `SuggestionChip`:\n\n\n```kotlin\n@Composable\nfun SuggestionChipExample() {\n SuggestionChip(\n onClick = { Log.d(\"Suggestion chip\", \"hello world\") },\n label = { Text(\"Suggestion chip\") }\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/Chip.kt#L153-L159\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows:\n**Figure 6.** Suggestion chip. **Note:** Although the suggestion chip component is intended for informational purposes, it does still take an `onClick` lambda that you can use to create interactivity.\n\nElevated chip\n\nAll the examples in this document use the base composables that take a flat\nappearance. If you want a chip that has an elevated appearance, use one of the\nthree following composables:\n\n- [`ElevatedAssistChip`](/reference/kotlin/androidx/compose/material3/package-summary#ElevatedAssistChip(kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.graphics.Shape,androidx.compose.material3.ChipColors,androidx.compose.material3.ChipElevation,androidx.compose.material3.ChipBorder,androidx.compose.foundation.interaction.MutableInteractionSource))\n- [`ElevatedFilterChip`](/reference/kotlin/androidx/compose/material3/package-summary#ElevatedFilterChip(kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.graphics.Shape,androidx.compose.material3.SelectableChipColors,androidx.compose.material3.SelectableChipElevation,androidx.compose.material3.SelectableChipBorder,androidx.compose.foundation.interaction.MutableInteractionSource))\n- [`ElevatedSuggestionChip`](/reference/kotlin/androidx/compose/material3/package-summary#ElevatedSuggestionChip(kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,androidx.compose.ui.graphics.Shape,androidx.compose.material3.ChipColors,androidx.compose.material3.ChipElevation,androidx.compose.material3.ChipBorder,androidx.compose.foundation.interaction.MutableInteractionSource))\n\nAdditional resources\n\n- [Material UI docs](https://m3.material.io/components/chips/overview)"]]