The Watch Face Format is required for watch faces to be installed on devices with Wear OS 5 or later pre-installed and for all new watch faces published on Google Play.
Starting in January 2026, the Watch Face Format will be required for watch faces to be installed on all Wear OS devices.
Learn more about the user-facing changes in this Help Center article.
Xử lý thao tác nhấn trên mặt đồng hồ
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Người dùng có thể tương tác với mặt đồng hồ của bạn theo nhiều cách.
Ví dụ: người dùng có thể nhấn vào mặt đồng hồ để biết bài hát đang phát hoặc để xem chương trình làm việc trong ngày. Với Wear OS by Google, mặt đồng hồ sẽ chấp nhận cử chỉ nhấn một lần tại một vị trí nhất định trên mặt đồng hồ, miễn là không có phần tử trên giao diện người dùng nào khác phản hồi với cử chỉ đó.
Để triển khai một mặt đồng hồ tương tác, trước tiên, hãy tạo kiểu mặt đồng hồ rồi triển khai cách xử lý cử chỉ như mô tả trong hướng dẫn này.
Xử lý sự kiện nhấn
Mặt đồng hồ chỉ nhận các sự kiện nhấn. Đây là những sự kiện mà người dùng đặt ngón tay xuống màn hình rồi nhấc ngón tay lên. Nếu người dùng thực hiện loại cử chỉ nào khác trong khi ngón tay đang nằm trên màn hình cảm ứng, thì mặt đồng hồ sẽ nhận được một sự kiện huỷ, vì mọi cử chỉ khác đã được hệ thống đặt trước cho các chức năng khác.
Để xử lý các cử chỉ nhấn, hãy sử dụng setTapListener()
để thêm TapListener
.
Trình nghe này được gọi mỗi khi người dùng nhấn vào mặt đồng hồ.
Mặt đồng hồ sẽ nhận các loại sự kiện chạm sau đây:
-
TapType.DOWN
: khi người dùng đặt ngón tay xuống màn hình cảm ứng
-
TapType.UP
: khi người dùng nhấc ngón tay lên khỏi màn hình cảm ứng
-
TapType.CANCEL
: khi hệ thống phát hiện thấy người dùng thực hiện một cử chỉ không phải là cử chỉ nhấn
Sự kiện TapType.DOWN
và sự kiện TapType.UP
liên tiếp được xác minh là một lượt nhấn theo giá trị mà android.view.ViewConfiguration.getScaledTouchSlop
trả về.
Đừng kích hoạt thao tác khi mặt đồng hồ nhận được sự kiện TapType.CANCEL
vì hệ thống đã xử lý cử chỉ này.
Để biết thêm thông tin, hãy xem onTapEvent
.
Ứng dụng mẫu về mặt đồng hồ minh hoạ các phương pháp hay nhất để định cấu hình mặt đồng hồ.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[],null,["# Handle taps in watch faces\n\nA user can interact with your watch face in many ways.\nFor example, a user might tap the watch face to learn what song is currently playing or\nto see the day's agenda. Wear OS by Google lets watch faces accept\nthe single-tap gesture at a given location on the watch face, as long as there's not another\nUI element that also responds to that gesture.\n\nTo implement an interactive watch face, first construct the\nwatch face style, and then implement gesture handling as described in this guide.\n\nHandle tap events\n-----------------\n\nThe watch face is only given tap events, which are events where the user puts a finger\ndown on the screen and then lifts it. If the user performs any other\ntype of gesture while their finger is on the touchscreen, the watch face receives a\ncancel event, as all other gestures are reserved by the system for other functions.\n\n\nTo handle tap gestures, use\n[`setTapListener()`](/reference/kotlin/androidx/wear/watchface/WatchFace#setTapListener(androidx.wear.watchface.WatchFace.TapListener)) to add a\n[`TapListener`](/reference/kotlin/androidx/wear/watchface/WatchFace.TapListener).\nThe listener is called whenever the user taps on the watch face.\n\nThe watch face receives the following types of touch events:\n\n- TapType.DOWN:\n when the user puts their finger down on the touchscreen\n\n- TapType.UP:\n when the user lifts the finger from the touchscreen\n\n- TapType.CANCEL:\n when the system detects that the user performs a gesture other than a tap\n\nA\n`TapType.DOWN` event and the successive `TapType.UP`\nevent are verified as a tap according to the value returned by\n[android.view.ViewConfiguration.getScaledTouchSlop](/reference/android/view/ViewConfiguration#getScaledTouchSlop()).\n\nDon't trigger an action when the watch face receives a `TapType.CANCEL`\nevent, because the system is already processing the gesture.\n\nFor more information, see [onTapEvent](https://developer.android.com/reference/androidx/wear/watchface/WatchFace.TapListener#onTapEvent(kotlin.Int,androidx.wear.watchface.TapEvent,androidx.wear.watchface.ComplicationSlot)).\n\nRelated resources\n-----------------\n\n\nThe\n[watch face sample app](https://github.com/android/wear-os-samples) demonstrates the best practices for configuring a watch face."]]