A Toast in android displays a small piece of message to user indication the work done or any errors.

In this tutorial, android toast example is explained by showing with both short toast and long toast.

The syntax for toast is

 

 

context –> Activity in which you want toast to be displayed

text –> Text to be displayed as toast.

duration –> long or short time period

show() –> show is compulsory don’t miss it.

 

Creating a toast is simple, there are two types of toast

1) Short length toast

2) Long length toast

 

Toast can also be customized according to the user requirement by setting gravity for the toast.

 

Also we can create a layout for toast a display it in next tutorial i will show you how to make a custom toast using a layout just as you design for any other screen.

 

Can set toast duration as i said above we can handle the time for which the toast is appeared on the screen.

 

Lastly very important thing in a toast is showing it on the screen using

 

 

 

 

 

MainActivity.java

 

Add buttons to xml screen by using which we can select short and long toast to display.

 

activity_main.xml

Output :

 

toast1

toast2

 

If you have any query’s please share them below

Also like and share this tutorial.

If required full coding ask me below.

Show Buttons
Hide Buttons
Read previous post:
Android Tutorial on Intent

Close