Toast with Materail Design


Android also provides a toast, primarily used for system messaging. Toasts are similar to snackbars but do not contain actions and cannot be swiped off screen.
How to add?
Create Toast instance with make() method. Then call show() method.

To specify how long Toast will be visible on screen use duration parameter of makeText() method or setDuration method.
// you can use only those 2 predefined constants

To hide Toast manually at any time use cancel() method.

Close the view if it’s showing, or don’t show it if it isn’t showing yet. You do not normally have to call this. Normally view will disappear on its own after the appropriate duration.
To change position of Toast use setGravity() method.

How to style?
With code

With custom view
I. Declare your custom view inside of any layout.xml file.

II. Set your custom view to Toast via setView() method.

t1 t2

Leave a Reply