Android - Snackbar vs Toast - usage and difference

前端 未结 9 1951
温柔的废话
温柔的废话 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: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();
    

提交回复
热议问题