gpt4 book ai didi

Android - Snackbar vs Toast - 用法和区别

转载 作者:IT老高 更新时间:2023-10-28 13:06:59 30 4
gpt4 key购买 nike

到目前为止,我们一直在我们的应用程序中使用 Toast,并且由于我们计划采用支持设计库中的一些新功能,所以我想知道 Snackbar 与 Toast 的推荐用法是什么。

我一直在阅读 the google material snackbar doc.

Snackbars provide lightweight feedback about an operation in a small popup at the base of the screen on mobile and at the lower left on desktop. They are above all over elements on screen, including the FAB.

toast 。

Android also provides a capsule-shaped toast, primarily used for system messaging. Toasts are similar to snackbars but do not contain actions and cannot be swiped off screen.

我了解他们的工作,但我有点困惑何时使用什么。是不是意味着:

  • 如果我不需要用户交互,我会使用 toast 吗?
  • 什么是“系统消息”?这是否适用于在我的应用和 Android 系统之间发生重要事件时显示信息?
  • 我喜欢滑动屏幕功能 - 这会是开始用 snackbar 代替 toast 的理由吗? (虽然这是一个基于意见的问题)

最佳答案

If I don't require user interaction I would use a toast?

您仍然可以使用 Snackbar。对 Snackbar 进行操作不是强制性的。

What is meant by "system messaging"? Does that apply to displayinginformation when something important happened between my app and theAndroid system?

我相信这意味着如果有一些与系统有关的消息,将使用 Toast。整个 android 或您可能正在运行的某些后台服务。例如。 Text-To-Speech 未安装。未找到电子邮件客户端。

What I like is the swipe off screen feature - would that be a reasonto start replacing toasts with Snackbar? (this is a bit opinion basedquestion though)

这是一个原因。但还有其他几个优点。例如:即使 Activity 完成,您的 toast 也会保留在屏幕上。 Snackbar 不会。 如果在退出应用程序后很久没有弹出 Toast(或在按顺序创建多个 Toast 的情况下继续弹出),则困惑会减少。 Snackbar 不会发生这种情况。

最重要的是:我建议如果您正在考虑,您应该切换。 SnackBars 看起来比 Toasts 好得多。

关于Android - Snackbar vs Toast - 用法和区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34432339/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com