เคล็ดลับเครื่องมือ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ลองใช้วิธีการเขียน
Jetpack Compose เป็นชุดเครื่องมือ UI ที่แนะนำสำหรับ Android ดูวิธีเพิ่มคอมโพเนนต์ใน Compose
เคล็ดลับเครื่องมือคือข้อความอธิบายขนาดเล็กที่ปรากฏใกล้กับมุมมองเมื่อผู้ใช้
กดค้างที่มุมมองหรือวางเมาส์เหนือมุมมอง วิธีนี้มีประโยชน์เมื่อแอปของคุณ
ใช้ไอคอนแสดงการทำงานหรือส่วนของข้อมูลเพื่อประหยัดพื้นที่
เลย์เอาต์ หน้านี้แสดงวิธีเพิ่มเคล็ดลับเครื่องมือเหล่านี้ใน Android 8.0 (ระดับ API
26) ขึ้นไป
บางสถานการณ์ เช่น เหตุการณ์ในแอปเพื่อการทำงาน ต้องใช้วิธีการที่สื่อความหมาย
ในการสื่อสารแนวคิดและการกระทำ คุณสามารถใช้เคล็ดลับเครื่องมือเพื่อแสดง
ข้อความอธิบายที่แสดงในรูปที่ 1

รูปที่ 1 เคล็ดลับเครื่องมือที่แสดงในแอป Android
วิดเจ็ตมาตรฐานบางรายการจะแสดงเคล็ดลับเครื่องมือตามเนื้อหาของ title
หรือ
พร็อพเพอร์ตี้ content description
รายการ เริ่มตั้งแต่ Android 8.0 คุณสามารถระบุ
ข้อความที่แสดงในเคล็ดลับเครื่องมือ โดยไม่คำนึงถึงค่าของพร็อพเพอร์ตี้อื่นๆ
การตั้งค่าข้อความเคล็ดลับเครื่องมือ
คุณสามารถระบุข้อความเคล็ดลับเครื่องมือใน View
โดยเรียกเมธอด
setTooltipText()
วิธี คุณสามารถกำหนด
พร็อพเพอร์ตี้ tooltipText
โดยใช้แอตทริบิวต์ XML หรือ API ที่เกี่ยวข้อง
หากต้องการระบุข้อความเคล็ดลับเครื่องมือในไฟล์ 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-07-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-07-27 UTC"],[],[],null,["# Tooltips\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to add components in Compose. \n[Popup →](/reference/kotlin/androidx/compose/ui/window/package-summary#Popup(androidx.compose.ui.window.PopupPositionProvider,kotlin.Function0,androidx.compose.ui.window.PopupProperties,kotlin.Function0)) \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------------------------\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\n### Kotlin\n\n```kotlin\nval fab: FloatingActionButton = findViewById(R.id.fab)\nfab.tooltipText = \"Send an email\"\n```\n\n### Java\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."]]