Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Thành phần Chip là một phần tử giao diện người dùng nhỏ gọn, có tính tương tác. Thẻ này đại diện cho các thực thể phức tạp như người liên hệ hoặc thẻ, thường có biểu tượng và nhãn. Thông báo này có thể đánh dấu, đóng hoặc nhấp vào được.
Sau đây là 4 loại chip và nơi bạn có thể sử dụng chúng:
Hỗ trợ: Hướng dẫn người dùng trong một tác vụ. Thường xuất hiện dưới dạng một phần tử tạm thời trên giao diện người dùng để phản hồi thông tin đầu vào của người dùng.
Bộ lọc: Cho phép người dùng tinh chỉnh nội dung trong một nhóm lựa chọn. Bạn có thể chọn hoặc bỏ chọn các mục này và có thể thấy biểu tượng dấu kiểm khi chọn.
Đầu vào: Đại diện cho thông tin do người dùng cung cấp, chẳng hạn như lựa chọn trong một trình đơn. Chúng có thể chứa một biểu tượng và văn bản, đồng thời cung cấp một X để xoá.
Đề xuất: Đưa ra đề xuất cho người dùng dựa trên hoạt động hoặc thông tin đầu vào gần đây của họ. Thường xuất hiện bên dưới một trường nhập để nhắc người dùng thực hiện hành động.
Hình 1. Bốn thành phần khối.
Nền tảng API
Có 4 thành phần kết hợp tương ứng với 4 loại chip. Các phần sau đây trình bày chi tiết về những thành phần kết hợp này và sự khác biệt giữa chúng.
Tuy nhiên, chúng có chung các tham số sau:
label: Chuỗi xuất hiện trên khối thông tin.
icon: Biểu tượng xuất hiện ở đầu thẻ. Một số thành phần kết hợp cụ thể có tham số leadingIcon và trailingIcon riêng biệt.
onClick: Lambda mà khối gọi khi người dùng nhấn vào.
Khối hỗ trợ
Thành phần kết hợp AssistChip cung cấp một cách đơn giản để tạo chip hỗ trợ nhằm thúc đẩy người dùng theo một hướng cụ thể. Một điểm khác biệt là tham số leadingIcon cho phép bạn hiển thị một biểu tượng ở bên trái của chip. Ví dụ sau đây minh hoạ cách bạn có thể triển khai:
Thành phần kết hợp FilterChip yêu cầu bạn theo dõi xem chip có được chọn hay không. Ví dụ sau đây minh hoạ cách bạn chỉ có thể hiện biểu tượng đã đánh dấu ở đầu khi người dùng đã chọn chip:
Phương thức triển khai này có dạng như sau khi chưa được chọn:
Hình 3. Khối bộ lọc chưa được chọn.
Và sẽ xuất hiện như sau khi được chọn:
Hình 4. Khối bộ lọc đã chọn.
Khối nhập
Bạn có thể dùng thành phần kết hợp InputChip để tạo các khối thông tin xuất phát từ lượt tương tác của người dùng. Ví dụ: trong một ứng dụng email, khi người dùng đang viết email, một chip đầu vào có thể đại diện cho một người liên hệ mà người dùng đã thêm vào trường "Đến:".
Quy trình triển khai sau đây minh hoạ một chip đầu vào đã ở trạng thái được chọn. Người dùng đóng thẻ khi nhấn vào thẻ.
Thành phần kết hợp SuggestionChip là thành phần cơ bản nhất trong số các thành phần kết hợp được liệt kê trên trang này, cả về định nghĩa API và các trường hợp sử dụng phổ biến. Các gợi ý dạng nút cho thấy những gợi ý được tạo linh động. Ví dụ: trong một ứng dụng trò chuyện AI, bạn có thể sử dụng các đề xuất dạng chip để trình bày các câu trả lời có thể cho tin nhắn gần đây nhất.
Tất cả ví dụ trong tài liệu này đều sử dụng các thành phần kết hợp cơ bản có giao diện phẳng. Nếu bạn muốn một thành phần hiển thị có giao diện nổi, hãy dùng một trong 3 thành phần kết hợp sau:
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[],[],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)"]]