snackbar
In this tutorial we’ll discuss and implement various forms of Android Snackbar widget in our application.
在本教程中,我们将在应用程序中讨论和实现各种形式的Android Snackbar小部件。
Android Snackbar (Android Snackbar)
Snackbar in android is a new widget introduced with the Material Design library as a replacement of a Toast.
android中的Snackbar是随Material Design库引入的新小部件,可替代Toast。
Android Snackbar is light-weight widget and they are used to show messages in the bottom of the application with swiping enabled. Snackbar android widget may contain an optional action button.
Android Snackbar是轻巧的小部件,用于在启用滑动的情况下在应用程序底部显示消息。 Snackbar android小部件可能包含一个可选的操作按钮。
吐司和小吃店之间的区别 (Difference between Toast and Snackbar)
- A Toast messages can be customised and printed anywhere on the screen, but a Snackbar can be only showed in the bottom of the screen 可以自定义Toast消息并在屏幕上的任何位置打印,但Snackbar只能显示在屏幕底部
- A Toast message don’t have action button, but Snackbar may have action button optionally. Though, A Snackbar shouldn’t have more than one action button Toast消息没有操作按钮,但是Snackbar可能有操作按钮。 不过,小吃店不应有多个动作按钮
- Toast message cannot be off until the time limit finish, but Snackbar can be swiped off before the time limit 在时间限制完成之前,不能关闭Toast消息,但是可以在时间限制之前关闭Snackbar
Note: Toast message and Snackbar have display length property in common.
注意 :Toast消息和Snackbar具有共同的显示长度属性。
A code snippet to display a basic android Snackbar is shown below.
下面显示了显示基本android Snackbar的代码段。
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "www.journaldev.com", Snackbar.LENGTH_LONG);
snackbar.show();
In the above snippet make()
method accepts three parameters:
在上面的代码段中, make()
方法接受三个参数:
- coordinatorLayout : It is the root layout of the activity coordinatorLayout :它