在 Android 上實作觸覺技術
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
觸覺回饋是指透過觸覺感知到的一切。現代 Android 裝置通常會整合震動致動器,讓裝置刺激使用者的觸覺。這些馬達已大幅進步,不再像早期裝置那樣發出嘈雜的嗡嗡聲,Android 應用程式現在可以利用這些功能,為使用者提供更細緻、更深度的體驗。
以下幾頁將介紹振動相關的所有內容,從基本觸覺回饋到越來越複雜的振動波形和效果組合。
- 觸覺回饋設計原則
- 本頁面說明 Android 觸覺回饋支援的分類,以及設計觸覺回饋的指南。
- 為事件新增觸覺回饋
- 這個頁面會提供程式碼範例,說明如何透過不同方式為使用者互動提供觸覺回饋。
- 震動致動器入門
- 這個頁面會概略說明震動致動器的運作方式,這是建立自訂觸覺回饋的重要先決知識。
- 建立自訂觸覺技術效果
- 本頁面提供幾個範例,說明如何使用不同的觸覺 API,在 Android 應用程式中建立自訂效果。
- 新增觸覺回饋 API
- 本頁面是 Android 上各種觸覺回饋 API 的參考資料,也說明瞭何時及如何檢查是否有任何必要的裝置支援,以確保觸覺回饋效果能正常播放。
此外,請務必參閱無障礙功能最佳做法。
範例
您可以在 GitHub 的 Haptic Sampler 應用程式中找到下列範例。您也可以在這裡找到各項功能的說明文件。
本文件也提供下列自訂震動模式的程式碼範例:
影片
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","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-26 (世界標準時間)。"],[],[],null,["# Implement haptics on Android\n\nHaptics is everything you feel through the sense of touch. Modern Android\ndevices often incorporate a vibration actuator to allow devices to stimulate the\nuser's sense of touch. These motors have advanced significantly from the\noriginal loud buzzy vibration produced by early devices, and Android apps can\nnow take advantage of capabilities to give users a richer experience with\nsubtlety and depth.\n\nThe following pages cover everything about vibration, from basic haptic feedback\nto increasingly more complex vibration waveforms and effect compositions.\n\n[Haptics design principles](/develop/ui/views/haptics/haptics-principles)\n: The page describes the classifications supported by Android haptics and\n guidelines for designing them.\n\n[Add haptic feedback to events](/develop/ui/views/haptics/haptic-feedback)\n: The page presents code examples for different ways of providing haptic\n feedback to user interactions.\n\n[Vibration actuators primer](/develop/ui/views/haptics/actuators)\n: The page provides an overview of how vibration actuators work, which is\n important prerequisite knowledge for creating custom haptics.\n\n[Create custom haptic effects](/develop/ui/views/haptics/custom-haptic-effects)\n: This page provides several examples of using different haptics APIs to\n create custom effects in an Android application.\n\n[Add haptics APIs](/develop/ui/views/haptics/haptics-apis)\n: The page is a reference for various haptics APIs available on Android, and\n also covers when and how to check for any device support necessary to ensure\n your Haptic effects play as intended.\n\nAlso, be sure to read the\n[best practices for accessibility](/guide/topics/ui/accessibility).\n\nSamples\n-------\n\nThe following samples are available in the [Haptic Sampler app](https://github.com/android/platform-samples/tree/main/samples/user-interface/haptics) on\nGitHub. You can also find documentation for each here.\n\n- [Resist (with low ticks)](/develop/ui/views/haptics/custom-haptic-effects#resist)\n- [Expand (with rise and fall)](/develop/ui/views/haptics/custom-haptic-effects#expand)\n- [Wobble (with spins)](/develop/ui/views/haptics/custom-haptic-effects#wobble)\n- [Bounce (with thuds)](/develop/ui/views/haptics/custom-haptic-effects#bounce)\n\nThis documentation also includes code examples for the following custom vibration patterns:\n\n- [Ramp-up pattern](/develop/ui/views/haptics/custom-haptic-effects#ramp_up_pattern)\n- [Repeating pattern](/develop/ui/views/haptics/custom-haptic-effects#repeating_pattern)\n- [Pattern with fallback](/develop/ui/views/haptics/custom-haptic-effects#pattern_with_fallback)\n\nVideo\n-----"]]