codeofaninja
website

Android Toast Tutorial

Photo of Mike Dalisay
Modified Thursday, June 2, 2011
by - @ninjazhai
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! :)

The Code of a Ninja Resources

For FREE programming tutorials, click the red button below and subscribe! :)
Thanks for the comments!
 
 
Fundamentals
"First do it, then do it right, then do it better."
~ Addy Osmani
"Talk is cheap. Show me the code."
~ Linus Torvalds
Let's Stay Connected!
g+ r
Android app on Google Play
© 2011-2014 The Code Of A Ninja. All rights reserved. Proudly Powered by Google Blogger. Images, logos, marks or names mentioned herein are the property of their respective owners.