เคล็ดลับเครื่องมือ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ลองใช้ Compose
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-08-26 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-26 UTC"],[],[],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."]]