با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
دکمه عمل شناور (FAB) یک دکمه با تاکید زیاد است که به کاربر اجازه می دهد یک عمل اصلی را در یک برنامه انجام دهد. این یک اقدام متمرکز و منفرد را ترویج می کند که رایج ترین مسیری است که کاربر ممکن است طی کند و معمولاً در سمت راست پایین صفحه لنگر انداخته می شود.
این سه مورد استفاده را در نظر بگیرید که ممکن است از FAB استفاده کنید:
ایجاد مورد جدید : در یک برنامه یادداشت برداری، ممکن است از FAB برای ایجاد سریع یادداشت جدید استفاده شود.
افزودن مخاطب جدید : در یک برنامه چت، یک FAB میتواند رابطی را باز کند که به کاربر امکان میدهد فردی را به یک مکالمه اضافه کند.
مکان مرکزی : در یک رابط نقشه، یک FAB می تواند نقشه را بر روی مکان فعلی کاربر متمرکز کند.
در طراحی متریال، چهار نوع FAB وجود دارد:
FAB : یک دکمه اکشن شناور با اندازه معمولی.
Small FAB : یک دکمه اکشن شناور کوچکتر.
FAB بزرگ : یک دکمه اکشن شناور بزرگتر.
Extended FAB : یک دکمه اکشن شناور که شامل چیزی بیش از یک نماد نیست.
شکل 1. چهار نوع دکمه عمل شناور.
سطح API
اگرچه چندین ترکیب قابل ترکیب وجود دارد که می توانید از آنها برای ایجاد دکمه های اکشن شناور مطابق با طراحی متریال استفاده کنید، پارامترهای آنها تفاوت زیادی با هم ندارند. از جمله پارامترهای کلیدی که باید در نظر داشته باشید موارد زیر است:
onClick : تابعی که با فشار دادن دکمه توسط کاربر فراخوانی می شود.
containerColor : رنگ دکمه.
contentColor : رنگ نماد.
دکمه اکشن شناور
برای ایجاد یک دکمه اکشن شناور عمومی، از FloatingActionButton اصلی قابل ترکیب استفاده کنید. مثال زیر اجرای اساسی یک FAB را نشان می دهد:
برای ایجاد یک دکمه اکشن شناور کوچک، از SmallFloatingActionButton composable استفاده کنید. مثال زیر نحوه انجام این کار را با افزودن رنگ های سفارشی نشان می دهد.
برای ایجاد یک دکمه اکشن شناور بزرگ، از LargeFloatingActionButton composable استفاده کنید. این ترکیب بندی تفاوت قابل توجهی با نمونه های دیگر ندارد به غیر از این واقعیت که منجر به یک دکمه بزرگتر می شود.
میتوانید دکمههای اکشن شناور پیچیدهتری را با ExtendedFloatingActionButton ایجاد کنید. تفاوت اصلی بین آن و FloatingActionButton این است که پارامترهای icon و text اختصاصی دارد. آنها به شما این امکان را می دهند که دکمه ای با محتوای پیچیده تر ایجاد کنید که متناسب با محتوای آن باشد.
قطعه زیر نحوه پیاده سازی ExtendedFloatingActionButton را با مقادیر نمونه ارسال شده برای icon و text نشان می دهد.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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 بهوقت ساعت هماهنگ جهانی."],[],[],null,["A Floating Action Button (FAB) is a high-emphasis button that lets the user\nperform a primary action in an application. It promotes a single, focused action\nthat is the most common pathway a user might take and is typically found\nanchored to the bottom right of the screen.\n\nConsider these three use cases where you might use a FAB:\n\n- **Create new item**: In a note-taking app, a FAB might be used to quickly create a new note.\n- **Add new contact**: In a chat app, a FAB could open an interface that lets the user add someone to a conversation.\n- **Center location**: In a map interface, a FAB could center the map on the user's current location.\n\nIn Material Design, there are four types of FAB:\n\n- **FAB**: A floating action button of ordinary size.\n- **Small FAB**: A smaller floating action button.\n- **Large FAB**: A larger floating action button.\n- **Extended FAB**: A floating action button that contains more than just an icon.\n\n**Figure 1.** The four floating action button types.\n\nAPI surface\n\nAlthough there are several composables you can use to create floating action\nbuttons consistent with Material Design, their parameters don't differ greatly.\nAmong the key parameters you should keep in mind are the following:\n\n- `onClick`: The function called when the user presses the button.\n- `containerColor`: The color of the button.\n- `contentColor`: The color of the icon.\n\nFloating action button\n\nTo create a general floating action button, use the basic\n[`FloatingActionButton`](/reference/kotlin/androidx/compose/material3/package-summary#FloatingActionButton(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)) composable. The following example demonstrates a\nbasic implementation of a FAB:\n\n\n```kotlin\n@Composable\nfun Example(onClick: () -\u003e Unit) {\n FloatingActionButton(\n onClick = { onClick() },\n ) {\n Icon(Icons.Filled.Add, \"Floating action button.\")\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/FloatingActionButton.kt#L61-L68\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows:\n**Figure 2.** A floating action button.\n\nSmall button\n\nTo create a small floating action button, use the\n[`SmallFloatingActionButton`](/reference/kotlin/androidx/compose/material3/package-summary#SmallFloatingActionButton(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)) composable. The following example demonstrates\nhow to do so, with the addition of custom colors.\n\n\n```kotlin\n@Composable\nfun SmallExample(onClick: () -\u003e Unit) {\n SmallFloatingActionButton(\n onClick = { onClick() },\n containerColor = MaterialTheme.colorScheme.secondaryContainer,\n contentColor = MaterialTheme.colorScheme.secondary\n ) {\n Icon(Icons.Filled.Add, \"Small floating action button.\")\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/FloatingActionButton.kt#L83-L92\n```\n\n\u003cbr /\u003e\n\n| **Note:** Because the various FAB composables share many parameters, you can use the approach in this example to customize colors with other composables.\n\nThis implementation appears as follows:\n**Figure 3.** A small floating action button.\n\nLarge button\n\nTo create a large floating action button, use the\n[`LargeFloatingActionButton`](/reference/kotlin/androidx/compose/material3/package-summary#LargeFloatingActionButton(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)) composable. This composable is not\nsignificantly different from the other examples aside from the fact that it\nresults in a bigger button.\n\nThe following is a straightforward implementation of a large FAB.\n| **Note:** This example passes `CircleShape` as the value for the `shape` parameter, resulting in a round button, rather than a square with rounded borders. You can pass any instance of `Shape`, or set the value of `MaterialTheme.shape.large` to adjust it across your app.\n\n\n```kotlin\n@Composable\nfun LargeExample(onClick: () -\u003e Unit) {\n LargeFloatingActionButton(\n onClick = { onClick() },\n shape = CircleShape,\n ) {\n Icon(Icons.Filled.Add, \"Large floating action button\")\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/FloatingActionButton.kt#L96-L104\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows:\n**Figure 4.** A large floating action button.\n\nExtended button\n\nYou can create more complex floating action buttons with the\n[`ExtendedFloatingActionButton`](/reference/kotlin/androidx/compose/material3/package-summary#ExtendedFloatingActionButton(kotlin.Function0,kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource)) composable. The key difference between it\nand [`FloatingActionButton`](/reference/kotlin/androidx/compose/material3/package-summary#FloatingActionButton(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)) is that it has dedicated `icon` and `text`\nparameters. They let you create a button with more complex content that scales\nto fit its content appropriately.\n\nThe following snippet demonstrates how to implement\n`ExtendedFloatingActionButton`, with example values passed for `icon` and\n`text`.\n\n\n```kotlin\n@Composable\nfun ExtendedExample(onClick: () -\u003e Unit) {\n ExtendedFloatingActionButton(\n onClick = { onClick() },\n icon = { Icon(Icons.Filled.Edit, \"Extended floating action button.\") },\n text = { Text(text = \"Extended FAB\") },\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/FloatingActionButton.kt#L72-L79\n```\n\n\u003cbr /\u003e\n\nThis implementation appears as follows:\n**Figure 5.** A floating action button with both text and an icon.\n\nAdditional resources\n\n- [Common buttons](/develop/ui/compose/components/button)\n- [Material UI docs](https://m3.material.io/components/floating-action-button/overview)"]]