工具提示
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
試試 Compose
Jetpack Compose 是 Android 推薦的 UI 工具包。瞭解如何在 Compose 中新增元件。
工具提示是簡短的描述性訊息,當使用者長按檢視區塊或將滑鼠遊標懸停在檢視區塊上時,旁邊就會顯示提示訊息。如果應用程式使用圖示來呈現動作或資訊,以便節省版面配置中的空間,這個方法就很有用。本頁面說明如何在 Android 8.0 (API 級別 26) 以上版本中新增工具提示。
在某些情境下 (例如在效率提升應用程式中),需要以描述性的方式來傳達想法和動作。您可以使用工具提示來顯示描述性訊息,如圖 1 所示。

圖 1. Android 應用程式中顯示的工具提示。
部分標準小工具會根據 title
或 content description
屬性的內容顯示工具提示。從 Android 8.0 版開始,您可以指定工具提示中顯示的文字,無需考慮其他屬性的值。
設定工具提示文字
呼叫 setTooltipText()
方法,即可在 View
中指定工具提示文字。您可以使用相應的 XML 屬性或 API 設定 tooltipText
屬性。
如要在 XML 檔案中指定工具提示文字,請設定 android:tooltipText
屬性,如以下範例所示:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:tooltipText="Send an email" />
如要在程式碼中指定工具提示文字,請使用 setTooltipText(CharSequence)
方法,如以下範例所示:
Kotlin
val fab: FloatingActionButton = findViewById(R.id.fab)
fab.tooltipText = "Send an email"
Java
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setTooltipText("Send an email");
API 也包含 getTooltipText()
方法,可用來擷取 tooltipText
屬性的值。
當使用者將滑鼠游標懸停在檢視區塊上,或是長按檢視區塊時,Android 會顯示 tooltipText
屬性的值。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-26 (世界標準時間)。
[null,null,["上次更新時間:2025-08-26 (世界標準時間)。"],[],[],null,["Try the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to add components in Compose. \n[Tooltip →](/develop/ui/compose/components/tooltip) \n\n\u003cbr /\u003e\n\nA tooltip is a small descriptive message that appears near a view when users\nlong press the view or hover their mouse over it. This is useful when your app\nuses an icon to represent an action or piece of information to save space in the\nlayout. This page shows you how to add these tooltips on Android 8.0 (API level\n26) and higher.\n\nSome scenarios, such as those in productivity apps, require a descriptive method\nof communicating ideas and actions. You can use tooltips to display a\ndescriptive message, as shown in figure 1.\n\n**Figure 1.** Tooltip displayed in an Android app.\n\nSome standard widgets display tooltips based on the content of the `title` or\n`content description` properties. Starting in Android 8.0, you can specify the\ntext displayed in the tooltip regardless of the value of other properties.\n\nSetting the tooltip text\n\nYou can specify the tooltip text in a [View](/reference/android/view/View) by calling the\n[setTooltipText()](/reference/android/view/View#setTooltipText(java.lang.CharSequence)) method. You can set\nthe `tooltipText` property using the corresponding XML attribute or API.\n\nTo specify the tooltip text in your XML files, set the [android:tooltipText](/reference/android/R.styleable#View_tooltipText) attribute, as shown\nin the following example: \n\n \u003candroid.support.design.widget.FloatingActionButton\n android:id=\"@+id/fab\"\n android:tooltipText=\"Send an email\" /\u003e\n\nTo specify the tooltip text in your code, use the [setTooltipText(CharSequence)](/reference/android/view/View#setTooltipText(java.lang.CharSequence)) method, as shown in the following example: \n\nKotlin \n\n```kotlin\nval fab: FloatingActionButton = findViewById(R.id.fab)\nfab.tooltipText = \"Send an email\"\n```\n\nJava \n\n```java\nFloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);\nfab.setTooltipText(\"Send an email\");\n```\n\nThe API also includes a [getTooltipText()](/reference/android/view/View#getTooltipText()) method that\nyou can use to retrieve the value of the `tooltipText` property.\n\nAndroid displays the value of the `tooltipText` property when users hover their\nmouse over the view or long press the view."]]