Android Toast Tutorial

What is Android Toast? The Android Toast is a view containing a quick little message for the user. When the toast is shown to the user, appears as a floating view over the application so it will never receive focus. The idea is to be as unobtrusive as possible, for example you want to instantly display information to user while they are using the your app. This tutorial will show you how to create a simple Android Toast using the toast class.

Android Toast Tutorial

I feel hungry now. :))

package com.example.AndroidToastTutorial;

import android.app.Activity;
import android.os.Bundle;
//import the toast widget
import android.widget.Toast;

public class AndroidToastTutorial extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //"This is the Toast message" will appear when you run this code
        Toast.makeText(getBaseContext(), "This is the Toast message", Toast.LENGTH_SHORT).show();
    }
}

The output of this code will look like the lower part of the image above (below the android logo and toasted bread). More info here. So that’s it! :)

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *