Android NDK开发详解Wear之在 Wear 上显示确认内容

Android NDK开发详解Wear之在 Wear 上显示确认内容


注意:本指南探讨的是使用 Android View 的方案。请考虑使用 Compose for Wear OS,这是一种新的声明式方法,用于根据最新 Material 准则在穿戴式设备上构建界面。借助 Jetpack Compose,您可以通改更少的代码编写出更出色的应用。
确认动画会在用户完成操作时向其提供视觉反馈。 它们会覆盖整个屏幕,确保用户可以一目了然地查看这些确认信息。

在大多数情况下,您无需使用单独的确认动画。请查看设计原则了解详情。

Jetpack Wear 界面库提供了 ConfirmationActivity,用于在应用中显示确认动画。

This Activity is used to display confirmation animations after the user completes an action on the wearable. There are three types of confirmations: Success: the action was completed successfully on the wearable. Failure: the action failed to complete. Open on Phone: the action has caused something to display on the phone, or in order to complete the action, the user will need to go to their phone to continue.

It is the responsibility of the wearable application developer to determine whether the action has succeeded, failed, or requires the user to go to their phone, and trigger the appropriate confirmation.

To configure the confirmation according to the result of the action, set the extra EXTRA_ANIMATION_TYPE to one of the following values:

SUCCESS_ANIMATION

Displays a positive confirmation animation with an optional message.
OPEN_ON_PHONE_ANIMATION

Displays an animation indicating an action has been sent to a paired device.
FAILURE_ANIMATION

Displays a generic failure page with an optional message.
An optional message, included in the extra EXTRA_MESSAGE will be displayed horizontally centered below the animation.

An optional duration in milliseconds to keep the confirmation activity visible for, included in the extra EXTRA_ANIMATION_DURATION_MILLIS

显示确认动画

ConfirmationActivity 用于当用户在穿戴式设备上完成某个操作后显示确认动画。

确认内容有三种类型:

成功:已成功在穿戴式设备上完成操作。
失败:未能完成操作。
在手机上打开:操作导致在手机上显示某些内容,或者为了完成该操作,用户需要转到手机上继续操作。
如需当用户在您的应用内完成某项操作时显示确认动画,请创建一个从您的某个 activity 启动 ConfirmationActivity 的 intent。将 EXTRA_ANIMATION_TYPE 设置为以下值之一:

SUCCESS_ANIMATION
FAILURE_ANIMATION
OPEN_ON_PHONE_ANIMATION

如需在您的应用中使用 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):2023-11-13。

  • 22
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五一编程

程序之路有我与你同行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值