Loading...

Android Toast - How to Display Simple Toast Message in Android

An android toast displays small message to the users about an operation without user input. Toast is displayed in front of the activity and it remains visible for a short time. Normally, android toast is displayed at the bottom of screen, you can also change display position. You can make custom design for toast using xml layout. Nowadays, most of the android application use Snackbar instead of toast.

In this example, I will show how to display simple android toast in your app.

Android Toast Example - How to Display Toast Message in AndroidRelated:
Android Snackbar Using Design Support Library
Custom Android Toast - How to Create a Custom Toast in Android

How to Display a Toast in Android


To display toast in your application, you have to use makeText() method. Use following toast, one is used to display for long period of time and another is used to display for short period of time. Use following code in onClick() method.
// display toast in long period of time
Toast.makeText(getApplicationContext(),"This is my toast message",Toast.LENGTH_LONG).show();

// display toast in short period of time
Toast.makeText(getApplicationContext(),"This is my toast message",Toast.LENGTH_LONG).show();
Modified code of activity layout file looks like this.
res/layout/activity_main.xml

Modified code of Java Activity looks like this.
src/MainActivity.java

That's all. Now, run your application that looks like this.

Simple Android Toast Example
Android Toast Example
Tech Tip
Android developers can now stay 24*7 workaholic by remotely accessing their android development and testing tools on any device(PC/android/iOS) with powerful hosted virtual desktops from CloudDesktopOnline. You can also add MS office to the same desktop by visiting O365CloudExperts.com. If you prefer a server, Rent a server from Apps4Rent.com with 24*7 dedicated migration and tech-support.
Tutorial 7652412257078391310
Home item