A toast in android returns a small feedback message to user indication the work done or any errors.It’s a light weight method.

In this tutorial a toast is explained by showing with both short toast and long toast.

The syntax for toast isĀ  Toast.makeText(context, text, duration).show();

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

 

MainActivity.java

 

Add buttons to xml screen.

 

activity_main.xml

Output :

 

toast1

toast2

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

Close