با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
از نکات ابزار برای افزودن زمینه به یک دکمه یا دیگر عنصر رابط کاربری استفاده کنید. دو نوع راهنمای ابزار وجود دارد:
نکات ساده ابزار : عناصر یا عملکردهای دکمههای نماد را توصیف کنید.
نکات ابزار غنی : جزئیات بیشتری را ارائه دهید، مانند توصیف ارزش یک ویژگی. همچنین میتواند شامل عنوان، پیوند و دکمههای اختیاری باشد.
شکل 1. یک ابزار ساده (1) و یک راهنمای ابزار غنی (2).
سطح API
می توانید از TooltipBox composable برای پیاده سازی راهنمای ابزار در برنامه خود استفاده کنید. شما ظاهر TooltipBox را با این پارامترهای اصلی کنترل می کنید:
positionProvider : راهنمای ابزار را نسبت به محتوای انکر قرار می دهد. شما معمولاً از یک ارائهدهنده موقعیت پیشفرض از TooltipDefaults استفاده میکنید، یا اگر به منطق موقعیتیابی سفارشی نیاز دارید، میتوانید موقعیت خود را ارائه کنید.
tooltip : قابل ترکیب که حاوی محتوای راهنمای ابزار است. شما معمولاً از ترکیبپذیرهای PlainTooltip یا RichTooltip استفاده میکنید.
از PlainTooltip برای توصیف عناصر یا عملکرد دکمههای نماد استفاده کنید.
از RichTooltip برای ارائه جزئیات بیشتر، مانند توصیف ارزش یک ویژگی، استفاده کنید. نکات ابزار غنی می تواند شامل عنوان، پیوند و دکمه های اختیاری باشد.
state : دارنده حالت که حاوی منطق UI و حالت عنصر برای این راهنمای ابزار است.
content : محتوای قابل ترکیبی که راهنمای ابزار به آن متصل شده است.
یک راهنمای ابزار ساده را نمایش دهید
از یک راهنمای ابزار ساده برای توصیف مختصر یک عنصر UI استفاده کنید. این قطعه کد یک راهنمای ابزار ساده را در بالای دکمه آیکون با برچسب "افزودن به موارد دلخواه" نشان می دهد:
@ComposablefunPlainTooltipExample(modifier:Modifier=Modifier,plainTooltipText:String="Add to favorites"){TooltipBox(modifier=modifier,positionProvider=TooltipDefaults.rememberPlainTooltipPositionProvider(),tooltip={PlainTooltip{Text(plainTooltipText)}},state=rememberTooltipState()){IconButton(onClick={/* Do something... */}){Icon(imageVector=Icons.Filled.Favorite,contentDescription="Add to favorites")}}}
IconButton یک دکمه قابل کلیک با یک نماد ایجاد می کند.
Icon(...) یک نماد قلب را در داخل دکمه نمایش می دهد.
هنگامی که کاربر با IconButton تعامل می کند، TooltipBox راهنمای ابزار را با متن "افزودن به موارد دلخواه" نشان می دهد. بسته به دستگاه، کاربران می توانند راهنمای ابزار را به روش های زیر فعال کنند:
با مکان نما روی نماد حرکت کنید
فشردن طولانی نماد روی دستگاه تلفن همراه
نتیجه
این مثال یک راهنمای ابزار ساده در بالای یک نماد تولید می کند:
شکل 2. یک راهنمای ابزار ساده که وقتی کاربر روی نماد قلب قرار می گیرد یا برای مدت طولانی آن را فشار می دهد ظاهر می شود.
یک راهنمای ابزار غنی را نمایش دهید
از یک راهنمای ابزار غنی برای ارائه زمینه اضافی در مورد یک عنصر UI استفاده کنید. این مثال یک راهنمای ابزار غنی چند خطی با عنوانی ایجاد می کند که به یک Icon متصل است:
@ComposablefunRichTooltipExample(modifier:Modifier=Modifier,richTooltipSubheadText:String="Rich Tooltip",richTooltipText:String="Rich tooltips support multiple lines of informational text."){TooltipBox(modifier=modifier,positionProvider=TooltipDefaults.rememberRichTooltipPositionProvider(),tooltip={RichTooltip(title={Text(richTooltipSubheadText)}){Text(richTooltipText)}},state=rememberTooltipState()){IconButton(onClick={/* Icon button's click event */}){Icon(imageVector=Icons.Filled.Info,contentDescription="Show more information")}}}
TooltipBox شنوندگان رویداد را برای تعاملات کاربر مدیریت می کند و TooltipState بر این اساس به روز می کند. هنگامی که TooltipState نشان می دهد که راهنمای ابزار باید نشان داده شود، راهنمای ابزار Lambda اجرا می شود، و TooltipBoxRichTooltip نمایش می دهد. TooltipBox به عنوان لنگر و محفظه هم برای محتوا و هم برای راهنمای ابزار عمل می کند.
در این مورد، محتوا یک جزء IconButton است که رفتار کنش قابل لمس را ارائه میکند. هنگامی که به مدت طولانی (در دستگاه های لمسی) فشار داده می شود یا روی هر جایی از محتوای TooltipBox قرار می گیرد (مانند نشانگر ماوس)، راهنمای ابزار برای نمایش اطلاعات بیشتر نمایش داده می شود.
یک RichToolTip یک راهنمای ابزار را با عنوان نمایش می دهد و عمل را رد می کند.
هنگامی که فعال می شود، یا با فشار طولانی یا نگه داشتن ماوس روی محتوای ToolTipBox با اشاره گر ماوس، راهنمای ابزار برای حدود یک ثانیه نمایش داده می شود. میتوانید با ضربه زدن در جای دیگری از صفحه یا با استفاده از دکمه عمل رد کردن، این نکته ابزار را رد کنید.
هنگامی که عمل رد کردن اجرا می شود، سیستم برنامه ای را برای فراخوانی tooltipState.dismiss راه اندازی می کند. این تأیید میکند که اجرای اقدام در زمانی که راهنمای ابزار نمایش داده میشود مسدود نشده است.
onClick = coroutineScope.launch { tooltipState.show() } } یک coroutine را برای نمایش دستی راهنمای ابزار با استفاده از tooltipState.show راه اندازی می کند.
پارامتر action امکان افزودن عناصر تعاملی را به یک راهنمای ابزار، مانند یک دکمه، می دهد.
پارامتر caretSize اندازه پیکان راهنمای ابزار را تغییر می دهد.
نتیجه
این مثال موارد زیر را تولید می کند:
شکل 4. یک راهنمای ابزار غنی سفارشی با عمل رد کردن که به نماد دوربین متصل شده است.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و 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,["Use [tooltips](https://m3.material.io/components/tooltips/overview) to add context to a button or other UI element.\nThere are two types of tooltips:\n\n- **Plain tooltips**: Describe elements or actions of icon buttons.\n- **Rich tooltips**: Provide more detail, such as describing the value of a feature. Can also include an optional title, link, and buttons.\n\n**Figure 1.** A plain tooltip (1) and a rich tooltip (2).\n\nAPI surface\n\nYou can use the [`TooltipBox`](/reference/kotlin/androidx/compose/material3/package-summary#TooltipBox(androidx.compose.ui.window.PopupPositionProvider,kotlin.Function1,androidx.compose.material3.TooltipState,androidx.compose.ui.Modifier,kotlin.Function0,kotlin.Boolean,kotlin.Boolean,kotlin.Function0)) composable to implement tooltips in your app.\nYou control [`TooltipBox`](/reference/kotlin/androidx/compose/material3/package-summary#TooltipBox(androidx.compose.ui.window.PopupPositionProvider,kotlin.Function1,androidx.compose.material3.TooltipState,androidx.compose.ui.Modifier,kotlin.Function0,kotlin.Boolean,kotlin.Boolean,kotlin.Function0)) appearance with these main parameters:\n\n- `positionProvider`: Places the tooltip relative to the anchor content. You typically use a default position provider from the `TooltipDefaults`, or you can provide your own if you need custom positioning logic.\n- `tooltip`: The composable that contains the tooltip's content. You typically use either the `PlainTooltip` or `RichTooltip` composables.\n - Use `PlainTooltip` to describe elements or actions of icon buttons.\n - Use `RichTooltip` to provide more details, like describing the value of a feature. Rich tooltips can include an optional title, link, and buttons.\n- `state`: The state holder that contains the UI logic and element state for this tooltip.\n- `content`: The composable content that the tooltip is anchored to.\n\nDisplay a plain tooltip\n\nUse a plain tooltip to briefly describe a UI element. This code snippet displays\na plain tooltip on top of an icon button, labeled \"Add to favorites\":\n\n\n```kotlin\n@Composable\nfun PlainTooltipExample(\n modifier: Modifier = Modifier,\n plainTooltipText: String = \"Add to favorites\"\n) {\n TooltipBox(\n modifier = modifier,\n positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),\n tooltip = {\n PlainTooltip { Text(plainTooltipText) }\n },\n state = rememberTooltipState()\n ) {\n IconButton(onClick = { /* Do something... */ }) {\n Icon(\n imageVector = Icons.Filled.Favorite,\n contentDescription = \"Add to favorites\"\n )\n }\n }\n}\nhttps://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/components/Tooltips.kt#L74-L95\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- `TooltipBox` generates a tooltip with the text \"Add to favorites\".\n - [`TooltipDefaults.rememberPlainTooltipPositionProvider()`](/reference/kotlin/androidx/compose/material3/TooltipDefaults?#rememberPlainTooltipPositionProvider(androidx.compose.ui.unit.Dp)) provides default positioning for plain tooltips.\n - `tooltip` is a lambda function that defines the tooltip's content using the [`PlainTooltip`](/reference/kotlin/androidx/compose/material3/TooltipScope#(androidx.compose.material3.TooltipScope).PlainTooltip(androidx.compose.ui.Modifier,androidx.compose.ui.unit.DpSize,androidx.compose.ui.unit.Dp,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,kotlin.Function0)) composable.\n - `Text(plainTooltipText)` displays the text within the tooltip.\n - [`tooltipState`](/reference/kotlin/androidx/compose/material3/TooltipState) controls the state of the tooltip.\n- `IconButton` creates a clickable button with an icon.\n - `Icon(...)` displays a heart icon within the button.\n - When a user interacts with the `IconButton`, `TooltipBox` shows the tooltip with the text \"Add to favorites\". Depending on the device, users can trigger the tooltip in the following ways:\n - Hovering over the icon with a cursor\n - Long-pressing the icon on a mobile device\n\nResult\n\nThis example produces a plain tooltip on top of an icon:\n**Figure 2.**A plain tooltip that appears when a user hovers over or long-presses the heart icon.\n\nDisplay a rich tooltip\n\nUse a rich tooltip to provide additional context about a UI element. This\nexample creates a multi-line rich tooltip with a title that is anchored to an\n`Icon`:\n\n\n```kotlin\n@Composable\nfun RichTooltipExample(\n modifier: Modifier = Modifier,\n richTooltipSubheadText: String = \"Rich Tooltip\",\n richTooltipText: String = \"Rich tooltips support multiple lines of informational text.\"\n) {\n TooltipBox(\n modifier = modifier,\n positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),\n tooltip = {\n RichTooltip(\n title = { Text(richTooltipSubheadText) }\n ) {\n Text(richTooltipText)\n }\n },\n state = rememberTooltipState()\n ) {\n IconButton(onClick = { /* Icon button's click event */ }) {\n Icon(\n imageVector = Icons.Filled.Info,\n contentDescription = \"Show more information\"\n )\n }\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/components/Tooltips.kt#L106-L131\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- `TooltipBox` handles the event listeners for user interactions and updates `TooltipState` accordingly. When `TooltipState` indicates that the tooltip should be shown, the tooltip lambda executes, and `TooltipBox` displays the `RichTooltip`. The `TooltipBox` acts as the anchor and container for both content and the tooltip.\n - In this case, the content is an `IconButton` component, which provides the tappable action behavior. When long-pressed (on touch devices) or hovered over (as with the mouse pointer) anywhere in `TooltipBox`'s content, the tooltip will display to show more information.\n- The `RichTooltip` composable defines the tooltip's content, including the title and body text. [`TooltipDefaults.rememberRichTooltipPositionProvider()`](/reference/kotlin/androidx/compose/material3/TooltipDefaults?#rememberRichTooltipPositionProvider(androidx.compose.ui.unit.Dp)) provides positioning information for rich tooltips.\n\nResult\n\nThis example produces a rich tooltip with a title attached to an information\nicon:\n**Figure 3.**A rich tooltip with a title and an information icon.\n\nCustomize a rich tooltip\n\nThis code snippet displays a rich tooltip with a title, custom actions, and a\ncustom caret (arrow) displayed on top of a camera icon button:\n\n\n```kotlin\n@Composable\nfun AdvancedRichTooltipExample(\n modifier: Modifier = Modifier,\n richTooltipSubheadText: String = \"Custom Rich Tooltip\",\n richTooltipText: String = \"Rich tooltips support multiple lines of informational text.\",\n richTooltipActionText: String = \"Dismiss\"\n) {\n val tooltipState = rememberTooltipState()\n val coroutineScope = rememberCoroutineScope()\n\n TooltipBox(\n modifier = modifier,\n positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),\n tooltip = {\n RichTooltip(\n title = { Text(richTooltipSubheadText) },\n action = {\n Row {\n TextButton(onClick = {\n coroutineScope.launch {\n tooltipState.dismiss()\n }\n }) {\n Text(richTooltipActionText)\n }\n }\n },\n caretSize = DpSize(32.dp, 16.dp)\n ) {\n Text(richTooltipText)\n }\n },\n state = tooltipState\n ) {\n IconButton(onClick = {\n coroutineScope.launch {\n tooltipState.show()\n }\n }) {\n Icon(\n imageVector = Icons.Filled.Camera,\n contentDescription = \"Open camera\"\n )\n }\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/components/Tooltips.kt#L142-L187\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- A `RichToolTip` displays a tooltip with a title and dismiss action.\n- When activated, either by a long-press or hovering over the `ToolTipBox` content with the mouse pointer, the tooltip is displayed for about one second. You can dismiss this tooltip by either tapping elsewhere on the screen or using the dismiss action button.\n- When the dismiss action executes, the system launches a coroutine to call `tooltipState.dismiss`. This verifies the action execution isn't blocked while the tooltip is displayed.\n- `onClick = coroutineScope.launch { tooltipState.show() } }` launches a coroutine to manually show the tooltip using `tooltipState.show`.\n- The `action` parameter allows for the adding of interactive elements to a tooltip, such as a button.\n- The `caretSize` parameter modifies the size of the tooltip's arrow.\n\nResult\n\nThis example produces the following:\n**Figure 4.** A custom rich tooltip with a dismiss action anchored to a camera icon.\n\nAdditional resources\n\n- Material Design: [Tooltips](https://m3.material.io/components/tooltips/overview)"]]