קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
רכיב ה-Composable Card פועל כקונטיינר של Material Design לממשק המשתמש.
בדרך כלל, כל כרטיס מציג פריט תוכן אחד קוהרנטי. הנה כמה דוגמאות למקומות שבהם אפשר להשתמש בכרטיס:
מוצר באפליקציית שופינג.
כתבה חדשותית באפליקציית חדשות.
הודעה באפליקציית תקשורת.
ההתמקדות בהצגת פריט תוכן יחיד היא מה שמבדיל בין Card לבין מאגרי תוכן אחרים. לדוגמה, Scaffold מספק מבנה כללי למסך שלם. כרטיס הוא בדרך כלל רכיב קטן יותר בממשק המשתמש בתוך פריסה גדולה יותר, בעוד שרכיב פריסה כמו Column או Row מספק API פשוט וכללי יותר.
איור 1. דוגמה לכרטיס עם טקסט וסמלים.
הטמעה בסיסית
Card מתנהג בדומה למאגרים אחרים במצב כתיבה. מצהירים על התוכן שלו על ידי קריאה לרכיבים אחרים שניתנים להרכבה בתוכו. לדוגמה, בדוגמה המינימלית הבאה, הפונקציה Card מכילה קריאה לפונקציה Text:
אפשר לעיין בהפניה להגדרת ה-API של Card. הוא מגדיר כמה פרמטרים שמאפשרים לכם להתאים אישית את המראה וההתנהגות של הרכיב.
הנה כמה פרמטרים חשובים שכדאי לשים לב אליהם:
elevation: מוסיף צל לרכיב, כך שהוא נראה מורם מעל הרקע.
colors: משתמשת בסוג CardColors כדי להגדיר את צבע ברירת המחדל של הקונטיינר ושל כל רכיבי הצאצא.
enabled: אם מעבירים את הערך false לפרמטר הזה, הכרטיס מופיע כמושבת ולא מגיב לקלט של המשתמש.
onClick: בדרך כלל, Card לא מקבל אירועי קליק. לכן, העומס העיקרי שחשוב לציין הוא זה שמגדיר פרמטר onClick. כדאי להשתמש בעומס היתר הזה אם רוצים שההטמעה של Card תגיב ללחיצות של המשתמש.
בדוגמה הבאה אפשר לראות איך אפשר להשתמש בפרמטרים האלה, וגם בפרמטרים נפוצים אחרים כמו shape ו-modifier.
כרטיס מלא
בדוגמה הבאה אפשר לראות איך מטמיעים כרטיס מלא.
הדבר החשוב כאן הוא השימוש במאפיין colors כדי לשנות את צבע המילוי.
לכרטיסים אין פעולות גלילה או סגירה מובנות, אבל אפשר לשלב אותם עם קומפוזיציות שמציעות את התכונות האלה. לדוגמה, כדי להטמיע החלקה לסגירה בכרטיס, משלבים אותו עם הקומפוזיציה SwipeToDismiss. כדי לשלב עם גלילה, משתמשים בשינויים של גלילה כמו verticalScroll. מידע נוסף זמין במסמכי התיעוד של Scroll.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-27 (שעון 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-27 (שעון UTC)."],[],[],null,["The [`Card`](/reference/kotlin/androidx/compose/material3/package-summary#Card(androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.material3.CardColors,androidx.compose.material3.CardElevation,androidx.compose.foundation.BorderStroke,kotlin.Function1)) composable acts as a Material Design container for your UI.\nCards typically present a single coherent piece of content. The following are\nsome examples of where you might use a card:\n\n- A product in a shopping app.\n- A news story in a news app.\n- A message in a communications app.\n\nIt is the focus on portraying a single piece of content that distinguishes\n`Card` from other containers. For example, `Scaffold` provides general structure\nto a whole screen. Card is generally a smaller UI element inside a larger\nlayout, whereas a layout component such as `Column` or `Row` provides a simpler\nand more generic API.\n**Figure 1.** An example of a card populated with text and icons.\n\nBasic implementation\n\n`Card` behaves much like other containers in Compose. You declare its content by\ncalling other composables within it. For example, consider how `Card` contains a\ncall to `Text` in the following minimal example: \n\n @Composable\n fun CardMinimalExample() {\n Card() {\n Text(text = \"Hello, world!\")\n }\n }\n\n| **Note:** By default, a `Card` wraps its content in a `Column` composable, placing each item inside the card below one another.\n\nAdvanced implementations\n\nSee the [reference](/reference/kotlin/androidx/compose/material3/package-summary#Card(androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.material3.CardColors,androidx.compose.material3.CardElevation,androidx.compose.foundation.BorderStroke,kotlin.Function1)) for the API definition of `Card`. It defines several\nparameters that allow you customize the appearance and behavior of the\ncomponent.\n\nSome key parameters to note are the following:\n\n- **`elevation`**: Adds a shadow to the component that makes it appear elevated above the background.\n- **`colors`** : Uses the `CardColors` type to set the default color of both the container and any children.\n- **`enabled`** : If you pass `false` for this parameter, the card appears as disabled and does not respond to user input.\n- **`onClick`** : Ordinarily, a `Card` does not accept click events. As such, the primary overload you would like to note is that which defines an `onClick` parameter. You should use this overload if you would like your implementation of `Card` to respond to presses from the user.\n\nThe following example demonstrates how you might use these parameters, as well\nas other common parameters such as `shape` and `modifier`.\n| **Beta:** The `Card` overload that defines the `onClick` parameter is experimental.\n\nFilled card\n\nThe following is an example of how you can implement a filled card.\n\nThe key here is the use of the `colors` property to change the filled\ncolor.\n\n\n```kotlin\n@Composable\nfun FilledCardExample() {\n Card(\n colors = CardDefaults.cardColors(\n containerColor = MaterialTheme.colorScheme.surfaceVariant,\n ),\n modifier = Modifier\n .size(width = 240.dp, height = 100.dp)\n ) {\n Text(\n text = \"Filled\",\n modifier = Modifier\n .padding(16.dp),\n textAlign = TextAlign.Center,\n )\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/Card.kt#L106-L122\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows:\n**Figure 2.** Example of a filled card.\n\nElevated Card\n\nThe following snippet demonstrates how to implement an elevated card. Use the\ndedicated [`ElevatedCard`](/reference/kotlin/androidx/compose/material3/package-summary#ElevatedCard(androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.material3.CardColors,androidx.compose.material3.CardElevation,kotlin.Function1)) composable.\n\nYou can use the `elevation` property to control the appearance of elevation and\nthe resulting shadow.\n\n\n```kotlin\n@Composable\nfun ElevatedCardExample() {\n ElevatedCard(\n elevation = CardDefaults.cardElevation(\n defaultElevation = 6.dp\n ),\n modifier = Modifier\n .size(width = 240.dp, height = 100.dp)\n ) {\n Text(\n text = \"Elevated\",\n modifier = Modifier\n .padding(16.dp),\n textAlign = TextAlign.Center,\n )\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/Card.kt#L85-L101\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows:\n**Figure 3.** Example of an elevated card.\n\nOutlined Card\n\nThe following is an example of an outlined card. Use the dedicated\n[`OutlinedCard`](/reference/kotlin/androidx/compose/material3/package-summary#OutlinedCard(androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.material3.CardColors,androidx.compose.material3.CardElevation,androidx.compose.foundation.BorderStroke,kotlin.Function1)) composable.\n\n\n```kotlin\n@Composable\nfun OutlinedCardExample() {\n OutlinedCard(\n colors = CardDefaults.cardColors(\n containerColor = MaterialTheme.colorScheme.surface,\n ),\n border = BorderStroke(1.dp, Color.Black),\n modifier = Modifier\n .size(width = 240.dp, height = 100.dp)\n ) {\n Text(\n text = \"Outlined\",\n modifier = Modifier\n .padding(16.dp),\n textAlign = TextAlign.Center,\n )\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/Card.kt#L127-L144\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows:\n**Figure 4.** Example of an outlined card.\n\nLimitations\n\nCards don't come with inherent scroll or dismiss actions, but can integrate into\ncomposables offering these features. For example, to implement swipe to dismiss\non a card, integrate it with the [`SwipeToDismiss`](/reference/kotlin/androidx/compose/material3/package-summary#SwipeToDismiss(androidx.compose.material3.DismissState,kotlin.Function1,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.collections.Set)) composable. To integrate\nwith scroll, use scroll modifiers such as [`verticalScroll`](/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).verticalScroll(androidx.compose.foundation.ScrollState,kotlin.Boolean,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean)). See the [Scroll\ndocumentation](/develop/ui/compose/touch-input/pointer-input/scroll) for more information.\n\nAdditional resources\n\n- [Material UI docs](https://m3.material.io/components/cards/overview)"]]