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.
构建表盘服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
表盘主题是封装在 Wear OS 应用中的一种服务。当用户选择可用的表盘主题时,系统会显示该表盘主题并调用服务回调方法。
如果用户安装了包含表盘主题的 Wear OS 应用,可使用表盘主题选择器进行选择,在手表上显示相应表盘主题。或者也可以通过配对手机上的配套应用选择表盘。
本页将介绍如何配置 Wear OS 项目来包含表盘,以及如何实现表盘服务。
创建表盘项目
注意:我们建议您使用 Android Studio 开展 Wear OS 开发,因为使用它可以方便地进行项目设置、库收录和打包。
如需在 Android Studio 中为您的表盘主题创建项目,请完成以下步骤:
- 依次点击 File > New > New project。
- 在 Select a project template 窗口中,选择 Wear 标签页,再从选项列表中选择 Watch Face,然后点击 Next。
- 在 Configure your project 窗口中,接受默认值,然后点击 Finish。
Android Studio 会使用 app
模块为您的表盘主题服务创建项目。
依赖项
Android Studio 会自动在 build.gradle
文件中添加所需的依赖项。依赖项中包括 AndroidX 表盘主题库;如需详细了解此库,请参阅 GitHub 上的代码示例。
穿戴式设备支持库 API 参考
参考文档详细介绍了用于实现表盘的类。请浏览穿戴式设备支持库的 API 参考文档。
声明权限
表盘需要 WAKE_LOCK
权限。请将以下权限添加到 Wear OS 应用和手机应用清单文件中的 manifest
元素下:
<manifest ...>
<uses-permission
android:name="android.permission.WAKE_LOCK" />
<!-- Required for complications to receive complication data and open the provider chooser. -->
<uses-permission
android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA"/>
...
</manifest>
支持 direct-boot
您必须按照直接启动指南中的说明,在用户解锁之前使表盘可用:
- 在清单中将相应服务的
android:directBootAware
属性设置为 true
。
- 表盘应将信息存储在设备加密存储空间中。
实现服务和回调方法
Wear OS 中的表盘主题以 WatchFaceService
的形式实现。实现 WatchFaceService
需要创建三个对象:UserStyleSchema
、ComplicationSlotsManager
和 WatchFace
。
您可以通过替换 WatchFaceService
中的 3 个抽象方法来指定这 3 个对象,如下方示例所示:
Kotlin
class CustomWatchFaceService : WatchFaceService() {
/**
* The specification of settings the watch face supports.
* This is similar to a database schema.
*/
override fun createUserStyleSchema(): UserStyleSchema = // ...
/**
* The complication slot configuration for the watchface.
*/
override fun createComplicationSlotsManager(
currentUserStyleRepository: CurrentUserStyleRepository
): ComplicationSlotsManager = // ...
/**
* The watch face itself, which includes the renderer for drawing.
*/
override suspend fun createWatchFace(
surfaceHolder: SurfaceHolder,
watchState: WatchState,
complicationSlotsManager: ComplicationSlotsManager,
currentUserStyleRepository: CurrentUserStyleRepository
): WatchFace = // ...
}
注册表盘服务
实现表盘主题服务后,您需要在穿戴式应用的清单文件中注册实现。当用户安装此应用时,系统会使用该服务的相关信息将表盘主题显示在 Wear OS 配套应用和穿戴式设备上的表盘主题选择器中。
以下代码段展示了如何在 <application>
元素下注册表盘主题实现:
<service
android:name=".AnalogWatchFaceService"
android:label="@string/analog_name"
android:permission="android.permission.BIND_WALLPAPER" >
<meta-data
android:name="android.service.wallpaper"
android:resource="@xml/watch_face" />
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
android:resource="@drawable/preview_analog_circular" />
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
<category
android:name=
"com.google.android.wearable.watchface.category.WATCH_FACE" />
</intent-filter>
</service>
在向用户显示设备上安装的所有表盘主题时,Wear OS by Google 谷歌配套应用和穿戴式设备上的表盘主题选择器会使用 com.google.android.wearable.watchface.preview_circular
元数据条目定义的预览图片。若要获取这一可绘制对象,请在 Wear OS 设备上或模拟器实例中运行表盘主题并截取屏幕截图。在屏幕的像素密度为 HDPI 的 Wear 设备上,预览图片的大小一般为 320x320 像素。
android.service.wallpaper
元数据条目可指定 watch_face.xml
资源文件,该文件包含一个 wallpaper
元素,如以下示例所示:
<?xml version="1.0" encoding="UTF-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android" />
您的穿戴式应用可以包含多个表盘主题。您必须在穿戴式应用的清单文件中为每个表盘实现添加一个服务条目。
您还可以参阅以下相关资源:
本页面上的内容和代码示例受内容许可部分所述许可的限制。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,["# Build a watch face service\n\nA watch face is a [service](/guide/components/services)\npackaged in a [Wear OS app](/training/wearables/apps).\nWhen a user selects an available watch face, the watch face displays and the\nservice callback methods are invoked.\n\nWhen a user installs a Wear app that has watch faces, the watch\nfaces are available on the watch using the watch face selector.\nAlternatively, the user can select a watch face from a companion app on the paired phone.\n\nThis page describes how to configure a Wear OS project to include watch faces and how\nto implement a watch face service.\n\nCreate a watch face project\n---------------------------\n\n**Note:** We recommend that you use [Android Studio](/studio) for Wear OS development, as\nit provides project setup, library inclusion, and packaging conveniences.\n\nComplete the following steps to\n[create a project](/studio/projects/create-project#StartAProject)\nin Android Studio for your watch face:\n\n1. Click **File** \\\u003e **New** \\\u003e **New project**.\n2. In the **Select a project template** window, select the **Wear** tab, then select **Watch Face** from the list of options and click **Next**.\n3. In the **Configure your project** window, accept the default values and click **Finish**.\n\nAndroid Studio creates a project with an `app` module for your watch face service.\n\n### Dependencies\n\nAndroid Studio automatically adds the required dependencies in your `build.gradle`\nfiles. Included in the dependencies is the\n[AndroidX\nwatch face library](/reference/kotlin/androidx/wear/watchface/package-summary); see the\n[code sample](https://github.com/android/wear-os-samples/tree/main/WatchFaceKotlin) on GitHub for details about this library.\n\n### Wearable support library API reference\n\nThe reference documentation provides detailed information about the classes you use to\nimplement watch faces. Browse the\n[API reference\ndocumentation](/reference/android/support/wearable/watchface/package-summary) for the Wearable support library.\n\n### Declare permissions\n\nA watch face requires the `WAKE_LOCK` permission.\nAdd the following permission to the manifest files of both the Wear OS app\nand the mobile phone app under the `manifest` element: \n\n```xml\n\u003cmanifest ...\u003e\n \u003cuses-permission\n android:name=\"android.permission.WAKE_LOCK\" /\u003e\n\n \u003c!-- Required for complications to receive complication data and open the provider chooser. --\u003e\n \u003cuses-permission\n android:name=\"com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA\"/\u003e\n ...\n\u003c/manifest\u003e\n```\n\n### Support direct-boot\n\nYou must make your watchface available before user-unlock by following\n[Direct Boot](https://developer.android.com/training/articles/direct-boot) guidance:\n\n1. Set `android:directBootAware` attribute to `true` for your service in your manifest.\n2. Your watch face should store information in [device encrypted storage](https://developer.android.com/training/articles/direct-boot#access).\n\n\u003cbr /\u003e\n\nImplement the service and callback methods\n------------------------------------------\n\nWatch faces in Wear OS are implemented as a\n[`WatchFaceService`](/reference/kotlin/androidx/wear/watchface/WatchFaceService).\nImplementing a `WatchFaceService` requires creating three objects: a\n`UserStyleSchema`, a `ComplicationSlotsManager`, and a\n`WatchFace`.\n\nThese three objects are specified by overriding three abstract methods from\n`WatchFaceService`, shown in the following example: \n\n### Kotlin\n\n```kotlin\nclass CustomWatchFaceService : WatchFaceService() {\n\n /**\n * The specification of settings the watch face supports.\n * This is similar to a database schema.\n */\n override fun createUserStyleSchema(): UserStyleSchema = // ...\n\n /**\n * The complication slot configuration for the watchface.\n */\n override fun createComplicationSlotsManager(\n currentUserStyleRepository: CurrentUserStyleRepository\n ): ComplicationSlotsManager = // ...\n\n /**\n * The watch face itself, which includes the renderer for drawing.\n */\n override suspend fun createWatchFace(\n surfaceHolder: SurfaceHolder,\n watchState: WatchState,\n complicationSlotsManager: ComplicationSlotsManager,\n currentUserStyleRepository: CurrentUserStyleRepository\n ): WatchFace = // ...\n\n}\n```\n\nRegister the watch face service\n-------------------------------\n\nAfter you implement the watch face service, register the implementation in the manifest\nfile of the wearable app. When users install this app, the system uses the information about\nthe service to make the watch face available in the [Wear OS companion app](https://play.google.com/store/apps/details?id=com.google.android.wearable.app&hl=en) and in the watch face picker on the wearable device.\n\nThe following sample shows how to register a watch face implementation\nunder the [`\u003capplication\u003e`](/guide/topics/manifest/application-element) element: \n\n```xml\n\u003cservice\n android:name=\".AnalogWatchFaceService\"\n android:label=\"@string/analog_name\"\n android:permission=\"android.permission.BIND_WALLPAPER\" \u003e\n \u003cmeta-data\n android:name=\"android.service.wallpaper\"\n android:resource=\"@xml/watch_face\" /\u003e\n \u003cmeta-data\n android:name=\"com.google.android.wearable.watchface.preview_circular\"\n android:resource=\"@drawable/preview_analog_circular\" /\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.service.wallpaper.WallpaperService\" /\u003e\n \u003ccategory\n android:name=\n \"com.google.android.wearable.watchface.category.WATCH_FACE\" /\u003e\n \u003c/intent-filter\u003e\n\u003c/service\u003e\n```\n\nThe Wear OS by Google companion app and the watch face picker on the wearable device use the preview\nimage defined by the `com.google.android.wearable.watchface.preview_circular` metadata entry when\npresenting users with all the watch faces installed on the device. To obtain this drawable,\nrun the watch face on your Wear OS device or in an emulator instance and\n[take a screenshot](/studio/debug/am-screenshot). On Wear\ndevices with hdpi screens, the preview image is typically 320x320 pixels in size.\n\nThe `android.service.wallpaper` metadata entry specifies the\n`watch_face.xml` resource file, which contains a `wallpaper`\nelement, as shown in the following sample: \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cwallpaper xmlns:android=\"http://schemas.android.com/apk/res/android\" /\u003e\n```\n\nYour wearable app can contain more than one watch face. You must add a service entry to the\nmanifest file of the wearable app for each of your watch face implementations.\n\nRelated resources\n-----------------\n\n\nRefer to the following related resources:\n\n- [WatchFaceKotlin sample](https://github.com/android/wear-os-samples/tree/deprecated/WatchFaceKotlin)"]]