Android - Snackbar vs Toast - usage and difference

前端 未结 9 1832
温柔的废话
温柔的废话 2020-12-08 03:28

We have been using just Toasts in our application so far and as we are planning to adopt some new features from Support Design Library I am wondering what\'s the recommended

相关标签:
9条回答
  • 2020-12-08 04:17

    I would like to add a small comparison between toast and snack bar. In my opinion if your intention is to present a warning or info that need user interaction/acknowledgement, you should use a snack bar. If it is just an info message that doesn't need any user acknowledgement you can use toast.

    +---+----------------------------------------------------------------------+--------------------------------------------------------------------------+
    | # |                                Toast                                 |                                 Snackbar                                 |
    +---+----------------------------------------------------------------------+--------------------------------------------------------------------------+
    | 1 | Can’t be dismissed by swiping                                        | Can dismiss by swiping                                                   |
    | 2 | Activity not required (Can show in android home or above other apps) | Can show inside an activity of your app                                  |
    | 3 | Can’t handle user input                                              | Can handle user input                                                    |
    | 4 | Good for showing info messages to user                               | Good for showing warning/info type messages to user that needs attention |
    +---+----------------------------------------------------------------------+--------------------------------------------------------------------------+
    
    0 讨论(0)
  • 2020-12-08 04:19

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

    You can still use Snackbar. It is not mandatory to have an action with Snackbar.

    What is meant by "system messaging"? Does that apply to displaying information when something important happened between my app and the Android system?

    I believe this means that Toasts are to be used if there are some messages pertaining to the system. Either android as a whole or some background service you may be running. E.g. Text-To-Speech is not installed. OR No Email client found.

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

    That is one reason. But there are several other plus points. For an example: Your toast remains on screen even when the activity is finished. Snackbar doesn't. There is less confusion if the toast does not popup (or keep popping up in case of multiple Toast creation in sequence) long after the app is exited. This will not happen with Snackbar.

    More than everything: I suggest if you are thinking, you should switch. SnackBars look far better than Toasts.

    0 讨论(0)
  • 2020-12-08 04:19

    According to the official documentation at Pop-up messages overview:

    Note: The Snackbar class supersedes Toast. While Toast is currently still supported, Snackbar is now the preferred way to display brief, transient messages to the user.

    and (Material Design) Snackbars's documentation:

    Related concepts: Android also provides a Toast class with a similar API that can be used for displaying system-level notifications. Generally, snackbars are the preferred mechanism for displaying feedback messages to users, as they can be displayed in the context of the UI where the action occurred. Reserve Toast for cases where this cannot be done.

    0 讨论(0)
提交回复
热议问题