在 Android 上实现触感反馈
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
触感是指您通过触觉感知的一切。新型 Android 设备通常会集成振动致动器,以便设备刺激用户的触感。与早期设备产生的原始大声振动相比,这些马达已经有了显著进步,Android 应用现在可以利用这些功能为用户提供更细腻、更深层次的丰富体验。
以下页面介绍了与振动有关的所有内容,从基本触感反馈到越来越复杂的振动波形和效果组合。
- 触感反馈设计原则
- 此页面介绍了 Android 触感反馈支持的分类以及设计指南。
- 为事件添加触感反馈
- 此页面提供了有关以不同方式向用户互动提供触感反馈的代码示例。
- 振动致动器入门
- 本页面简要介绍了振动致动器的工作原理,这是创建自定义触感反馈的重要前提知识。
- 创建自定义触感反馈效果
- 本页提供了几个使用不同触感反馈 API 在 Android 应用中创建自定义效果的示例。
- 添加了触感反馈 API
- 本页面介绍了 Android 上提供的各种触感反馈 API,还介绍了何时以及如何检查是否需要任何设备支持,以确保触感反馈效果按预期播放。
此外,请务必阅读有关无障碍功能的最佳做法。
示例
GitHub 上的 Haptic Sampler 应用提供了以下示例。您还可以在此处找到每种类型的说明文档。
本文档还包含以下自定义振动模式的代码示例:
视频
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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-----"]]