Questions tagged [android-toast]

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:-

enter image description here

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

Toast overview

Toast developer guide

Toast code

Image Source and Brief guide

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]

639 questions
1207
votes
30 answers

Can't create handler inside thread that has not called Looper.prepare()

What does the following exception mean; how can I fix it? This is the code: Toast toast = Toast.makeText(mContext, "Something", Toast.LENGTH_SHORT); This is the exception: java.lang.RuntimeException: Can't create handler inside thread that has not…
michael
  • 106,540
  • 116
  • 246
  • 346
303
votes
32 answers

How to create Toast in Flutter

Can I create something similar to Toasts in Flutter? Just a tiny notification window that is not directly in the face of the user and does not lock or fade the view behind it.
Shady Aziza
  • 50,824
  • 20
  • 115
  • 113
301
votes
27 answers

Can an Android Toast be longer than Toast.LENGTH_LONG?

When using setDuration() for a Toast, is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG?
user268481
148
votes
9 answers

Android - Snackbar vs Toast - usage and difference

We have been using just Toasts in our application so far and as we are planning to adopt some new features from Support Design Library I am wondering what's the recommended usage for Snackbar vs. Toast. I have been reading on the google material…
Jakub Holovsky
  • 6,543
  • 10
  • 54
  • 98
127
votes
14 answers

How do you display a Toast from a background thread on Android?

How can I display Toast messages from a thread?
Arutha
  • 26,088
  • 26
  • 67
  • 80
103
votes
12 answers

How to display Toast at center of screen

In Android I want to display a toast message at the bottom of the screen, I tried this: Toast.makeText(test.this, "bbb", Toast.LENGTH_LONG).show(); It doesn't work, how do I do it correctly?
tedris
  • 1,118
  • 2
  • 7
  • 11
79
votes
6 answers

What does "toast" mean?

Curious what "Toast" means? Saw this and am curious... Similar Posts How to add toast style popup to my application? Program to show a "toast" notification popup from the Windows command line? Why does my text keep highlighting? Thread-safe…
madcolor
  • 8,105
  • 11
  • 51
  • 74
70
votes
11 answers

Center text in a Toast

I was wondering if there was a way to display all text in a Toast to be centered. For instance, I have a Toast that has 2 lines of text in it. For purely aesthetic reasons, I would like the text to center-aligned instead of left-aligned. I've looked…
Sonoman
  • 3,379
  • 9
  • 45
  • 61
67
votes
16 answers

How can I change default toast message color and background color in android?

I want to create a toast message with background color is white and message color is black. My toast message is: Toast.makeText(Logpage.this, "Please Give Feedback...", 3000).show(); I wanted to create it in another method not in onCreate().
Saranya
  • 733
  • 1
  • 6
  • 7
63
votes
8 answers

Adding image to Toast?

Is it possible to programmatically add an image to a toast popup?
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
45
votes
11 answers

How to avoid a Toast if there's one Toast already being shown

I have several SeekBar and onSeekBarProgressStop(), I want to show a Toast message. But if on SeekBar I perform the action rapidly then UI thread somehow blocks and Toast message waits till UI thread is free. Now my concern is to avoid the new Toast…
Deepak Goel
  • 5,624
  • 6
  • 39
  • 53
33
votes
4 answers

What is the value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT?

I am printing Toast message in my application to show notification but i want to know value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT. What other values i can use. Can anyone tell me what is the value of these two variables?
CoDe
  • 11,056
  • 14
  • 90
  • 197
29
votes
4 answers

IntentService won't show Toast

This IntentService I created will show Toasts in onStartCommand() and in onDestroy(), but not in onHandleIntent(). Am I missing something about the limitations of an IntentService? public class MyService extends IntentService { private static…
Tenfour04
  • 83,111
  • 11
  • 94
  • 154
25
votes
3 answers

How to create toast from IntentService? It gets stuck on the screen

I'm trying to have my IntentService show a Toast message, but when sending it from the onHandleIntent message, the toast shows but gets stuck and the screen and never leaved. I'm guessing its because the onHandleIntent method does not happen on the…
Omri
  • 1,087
  • 1
  • 11
  • 23
23
votes
12 answers

How can I show a toast for a specific duration?

This is the way I have to show the Toast for 500 milliseconds. Though, it's showing more than a second. Toast.makeText(LiveChat.this, "Typing", 500).show(); How can I show Toast only for 500 milliseconds?
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22
1
2 3
42 43