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.
绘制表盘
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
配置项目并添加用于实现表盘服务的类后,您便可以开始编写代码以初始化和绘制自定义表盘。
每个表盘都会创建一个渲染程序的自定义子类,用于实现绘制表盘所需的一切。
渲染程序结合使用 UserStyle
、ComplicationSlotsManager
中的复杂功能信息、当前时间和其他状态信息来渲染表盘,如以下示例所示:
class CustomCanvasRenderer(
private val context: Context,
surfaceHolder: SurfaceHolder,
watchState: WatchState,
private val complicationSlotsManager: ComplicationSlotsManager,
currentUserStyleRepository: CurrentUserStyleRepository,
canvasType: Int
) : Renderer.CanvasRenderer(
surfaceHolder = surfaceHolder,
currentUserStyleRepository = currentUserStyleRepository,
watchState = watchState,
canvasType = canvasType,
interactiveDrawModeUpdateDelayMillis = 16L
) {
override fun render(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {
// Draw into the canvas
}
override fun renderHighlightLayer(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {
// Draw into the canvas
}
}
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["After you configure your project and add a class that implements the\nwatch face service, you can start writing code to initialize and draw your\ncustom watch face.\n\nEvery watch face creates a custom subclass of a renderer that implements\neverything needed to draw the watch face.\n\nThe renderer combines the\n[`UserStyle`](/reference/androidx/wear/watchface/style/UserStyle), the\ncomplication information from\n[`ComplicationSlotsManager`](/reference/androidx/wear/watchface/ComplicationSlotsManager),\nthe current time, and other state information to\nrender the watch face, as shown in the following example: \n\n class CustomCanvasRenderer(\n private val context: Context,\n surfaceHolder: SurfaceHolder,\n watchState: WatchState,\n private val complicationSlotsManager: ComplicationSlotsManager,\n currentUserStyleRepository: CurrentUserStyleRepository,\n canvasType: Int\n ) : Renderer.CanvasRenderer(\n surfaceHolder = surfaceHolder,\n currentUserStyleRepository = currentUserStyleRepository,\n watchState = watchState,\n canvasType = canvasType,\n interactiveDrawModeUpdateDelayMillis = 16L\n ) {\n override fun render(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {\n // Draw into the canvas\n }\n\n override fun renderHighlightLayer(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {\n // Draw into the canvas\n }\n }"]]