在 Wear 上显示确认内容
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
试试 Compose 方式
Jetpack Compose on Wear OS 是适用于 Wear OS 的推荐界面工具包。
确认动画会在用户完成操作时向其提供视觉反馈。
它们会覆盖整个屏幕,确保用户可以一目了然地查看这些确认信息。
在大多数情况下,您无需使用单独的确认动画。请查看设计原则了解详情。
Jetpack Wear 界面库提供了 ConfirmationActivity
,用于在应用中显示确认动画。
显示确认动画
ConfirmationActivity
用于当用户在穿戴式设备上完成某个操作后显示确认动画。
确认内容有三种类型:
-
成功:已成功在穿戴式设备上完成操作。
-
失败:未能完成操作。
-
在手机上打开:操作导致在手机上显示某些内容,或者为了完成该操作,用户需要转到手机上继续操作。
如需当用户在您的应用内完成某项操作时显示确认动画,请创建一个从您的某个 activity 启动 ConfirmationActivity
的 intent。将 EXTRA_ANIMATION_TYPE
设置为以下值之一:
如需在您的应用中使用 ConfirmationActivity
,请先在清单文件中声明此 activity,如以下示例所示:
<manifest>
<application>
...
<activity
android:name="androidx.wear.activity.ConfirmationActivity">
</activity>
</application>
</manifest>
确定用户操作的结果,使用 intent 启动 activity,并添加一条要在确认图标下显示的消息,如以下示例所示:
val intent = Intent(this, ConfirmationActivity::class.java).apply {
putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.SUCCESS_ANIMATION)
putExtra(ConfirmationActivity.EXTRA_MESSAGE, getString(R.string.msg_sent))
}
startActivity(intent)
显示确认动画后,ConfirmationActivity
完成,您的 activity 继续。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Show confirmations on Wear\n\nTry the Compose way \nJetpack Compose on Wear OS is the recommended UI toolkit for Wear OS. \n[Try Compose on Wear OS →](/training/wearables/compose) \n\n\nConfirmation animations give users visual feedback when they complete an action.\nThey cover the entire screen to ensure that users can see these confirmations at a glance.\n\n\nIn most cases, you won't need to use a separate confirmation animation. Review\n[Design principles](/training/wearables/design/design-principles) for more information.\n\n\nThe Jetpack Wearable UI Library provides\n[ConfirmationActivity](/reference/androidx/wear/activity/ConfirmationActivity)\nto display a confirmation animation in your apps.\n\n### Show confirmation animations\n\n\n`ConfirmationActivity` is used to display confirmation animations after the user\ncompletes an action on the wearable.\n\n\nThere are three types of confirmations:\n\n- **Success**: the action was completed successfully on the wearable.\n- **Failure**: the action failed to complete.\n- **Open on Phone**: the action has caused something to display on the phone, or in order to complete the action, the user needs to go to their phone to continue.\n\n\nTo show a confirmation animation when users complete an action in your app, create an intent that\nstarts `ConfirmationActivity` from one of your activities. Set the\n[EXTRA_ANIMATION_TYPE](/reference/androidx/wear/activity/ConfirmationActivity#EXTRA_ANIMATION_TYPE)\nto one of the following values:\n\n- [SUCCESS_ANIMATION](/reference/androidx/wear/activity/ConfirmationActivity#SUCCESS_ANIMATION)\n- [FAILURE_ANIMATION](/reference/androidx/wear/activity/ConfirmationActivity#FAILURE_ANIMATION)\n- [OPEN_ON_PHONE_ANIMATION](/reference/androidx/wear/activity/ConfirmationActivity#OPEN_ON_PHONE_ANIMATION)\n\n\nTo use `ConfirmationActivity` in your app, first declare this activity in your\nmanifest file, as shown in the following example: \n\n```xml\n\u003cmanifest\u003e\n \u003capplication\u003e\n ...\n \u003cactivity\n android:name=\"androidx.wear.activity.ConfirmationActivity\"\u003e\n \u003c/activity\u003e\n \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\nDetermine the result of the user action, start the activity with an intent, and\nadd a message that appears under the confirmation icon, as shown in the following example: \n\n```kotlin\nval intent = Intent(this, ConfirmationActivity::class.java).apply {\n putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.SUCCESS_ANIMATION)\n putExtra(ConfirmationActivity.EXTRA_MESSAGE, getString(R.string.msg_sent))\n}\nstartActivity(intent)\n```\n\nAfter showing the confirmation animation, the\n`ConfirmationActivity` finishes and your activity resumes."]]