A Toast is a momentary popup in Android which provides simple feedback about an operation.
Summary
A Toast
is a momentary popup which provides simple feedback about an operation1. Toasts are added to an application's WindowManager and are not bound to an activity's UI; therefore, a Toast
can remain visible after an Activity
is navigated away from.
Toasts are typically displayed by using the makeText() method:
// also supports Toast.LENGTH_LONG
Toast.makeText(getApplicationContext(), "some message", Toast.LENGTH_SHORT).show();
Sample Toast:-
It is important to note that the duration parameter requires either the LENGTH_LONG or LENGTH_SHORT . A custom millisecond value is not a valid duration parameter.
Custom Toasts
Toasts can use a custom View
by using the setView() method3.
Usage
Toast
messages should be as unobtrusive as possible4. Toasts should be used in situations that necessitate the user to be notified of certain background tasks such as a setting or draft being saved. Generally, Toasts should not exceed a single line of text.
Further reading
References:
1http://developer.android.com/guide/topics/ui/notifiers/toasts.html [Accessed on March 10, 2015]
2http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.2_r1/android/widget/Toast.java#Toast.0LENGTH_SHORT [Accessed on March 10, 2015]
3http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView [Accessed on March 10, 2015]
4http://developer.android.com/reference/android/widget/Toast.html [Accessed on March 10, 2015]