Toast in Android Example

Toast in android is used to display a message on screen for a small period of time. Toast fades automatically after small time. Toast.LENGTH_SHORT and Toast.LENGTH_LONG are two constants to specify duration of Toast.

// Syntax to display Toast
Toast.makeText(context, "message", duration).show(); 

context – This is our application context.
message – Type a message here to display on screen.
duration – Time of toast to simply on screen.
show() – This method is used to display the toast.

// Example
Toast.makeText(MainActivity.this,"Toast Example message",Toast.LENGTH_LONG).show(); 

package com.androidaura.toast;

import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

      // Toast.makeText(context, text, duration).show();
         Toast.makeText(MainActivity.this, "Toast is Displayed", Toast.LENGTH_SHORT).show();


toast in android