Android - Snackbar vs Toast - usage and difference

前端 未结 9 1831
温柔的废话
温柔的废话 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:02

    The short answer is that those are 2 ways to communicate things to the user that happen in the background, and you can peak one of them, they both fine. Just make sure you're using the same one and not switching between them back and forth.

    The long answer:

    • No, that's mean that if you need some action you must use Snackbar. You can still use Snackbar only for messages (like "Uploading finished").
    • By "system" it doesn't mean just Android system. For example- if there was a json parsing problem while getting info from your server you can still use toast to let the user there was a problem while communicate with the server.
    • If you really need to swipe this off, that absultly be a reason to pick Snackbar
    0 讨论(0)
  • 2020-12-08 04:04

    Google's Material Design Specification says that it's ok to have a Snackbar without an action. They have provided examples of what a Snackbar should look like if it only displays a single String. I would assume that "System Messaging" means device events like network connection being lost - whereas archiving an email is a Gmail specific action, for example.

    For consistency's sake, it makes sense to pick either a Toast or a Snackbar, and apply that throughout your app.

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

    Difference between Toast and Snackbar Android

    • Toast messages can be customized and printed anywhere on the screen, but a Snackbar can be only shown in the bottom of the screen.
    • A Toast message doesn’t have action button, but Snackbar may have action button optionally.
    • Toast message cannot be off until the time limit finish, but Snackbar can be swiped off before the time limit.
    • You can set how long the message will be shown using this three different values.
        Snackbar.LENGTH_LONG
        Snackbar.LENGTH_SHORT
        Snackbar.LENGTH_INDEFINITE
    

    Usage

    Toast

    Toast.makeText(getApplicationContext(),"Hello",Toast.LENGTH_SHORT).show();
    

    Snackbar

    Snackbar snackbar = Snackbar.make(view,"This is Simple Snackbar",Snackbar.LENGTH_SHORT);
    snackbar.show();
    
    0 讨论(0)
  • 2020-12-08 04:09

    Our design team is looking at using either toasts or snackbars as well. We come to a conclusion that the app should be using snackbars given the flexibility of it.

    Toasts should only be used when we need a persistent, short string, info message that still make sense across different screens.

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

    Toast:

    1. Toast was added in API Level 1
    2. Basically Activity is not required (Can be shown on Android home or even above other apps)
    3. It can’t perform an action based on User input
    4. It can’t be dismissed by swiping
    5. It can’t handle user input like Swipe, Click etc.
    6. Good for showing info messages to user

    SnackBar:

    1. SnackBar was added in API Level 23
    2. It can be showed inside an activity of the Applications
    3. It can perform an action
    4. It can be dismissed by swiping
    5. It can handle user input
    6. Good for showing warning/info type messages to user that needs attention

    Usage of SnackBar and Toast:

    SnackBar:

    SnackBar can be used in the areas where a simple popup message needs to be displayed along with an option to perform action. For Example: In GMail application, when you delete Mail, quick SnackBar display at the bottom with Message ‘1 Deleted’ with an action button ‘Undo’. On pressing the ‘Undo’ action button, the deleted mail will be restored.

    Toast:

    Toast can be used in the areas where System messages need to be displayed.

    For Example:

    When your App tries to download JSON from remote server but it fails due to Server Timeout or No resource found, you just need to display the error message saying that ‘Error Occurred’. But understand the Toast message cannot be dismissed by swiping. If you still want to have the capability of dismissing it in your App, go for SnackBar.

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

    Android also provides a capsule-shaped toast, primarily used for system messaging.

    I think with "system messaging" they also refer to the fact that a toast will be shown for a specific time and can not be dismissed even if the user navigates across activities and even if the app is moved to background.

    I consider it an advantage of snackbar to limit its scope to an activity and to be able to dismiss it.

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