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
4
votes
6 answers

How To Disable Native Toast Messages

I am creating an application that implements a remote. One of the buttons on the remote turns the volume up and down. I have this button on the remote do something different because adjusting the volume in my application is irrelevant. So, my…
Ethan
  • 1,905
  • 2
  • 21
  • 50
4
votes
1 answer

Customize Android Talkback in Toast

I've checked with all default Toast message via Android TalkBack. Default Android Talkback behavior is that it reads all contents(non stop) in Toast. Is there any way I can customize it according to my need. For example :…
4
votes
1 answer

All my Toasts' text are being displayed off center

How do I fix this? I have not done anything to theme TextAppearance - I am simply using AppCompatActivity and Theme.AppCompat.NoActionBar. Could this be a bug in the support library?
ZakTaccardi
  • 12,212
  • 15
  • 59
  • 107
4
votes
1 answer

Android WebView showToast onButtonClick

I am developing an application that uses WebView to display a webpage. The webpage contains a registration form and a "next" button. I want to know if it is possible to show Android toast message if the users presses next, but has failed to fill the…
4
votes
3 answers

Prevent toast Message from getting cancelled on touch

I am developing a game in which I am displaying toast messages for instructions. The problem is as soon as the user touches the screen, toast message is getting cancelled. How can I prevent onTouch event from cancelling toast message? Code used to…
pratick
  • 303
  • 1
  • 3
  • 9
4
votes
4 answers

Android : Click through Toast

Upon clicking a button, a toast(with image) appears. This toast appears on top of another button. Now i want to click this another button while Toast is still there. It takes some time for the toast to disappear. Meanwhile if user wants to click the…
Russell
  • 361
  • 1
  • 8
  • 24
3
votes
1 answer

Toast fails to show when within a AsyncTask

I have a simple application which sends an image (Base64 encoded) to a server, the server gets this data fine because the PHP script sends me an email with the Base64 Data attached. However, after the task gets completed the toast never shows. How…
dotty
  • 40,405
  • 66
  • 150
  • 195
3
votes
1 answer

how to show toast if auth failed jetpack compose firebase if else @Composable invocations can only happen from the context of a @Composable function

There appear to be an infinite number of explanations for this error on stackoverflow, none of which address my issue. I want to show a toast if the authentication failed I am using firebase auth but the error is with the Location context how can I…
3
votes
3 answers

Toast does not show on screen

I am sorry if it is a too simple question. I have searched everywhere, but could not find a solution. For about 3 days Toast does not show up on my app. I tried to do a lot of things. Change makeText(this) to makeText(getApplicationContext()) or…
Jakhongir
  • 112
  • 1
  • 7
3
votes
0 answers

How to mimic the Toast-like View of long-pressing the action item of a Toolbar?

Background Long pressing an action-item of a Toolbar, you get a temporary Toast-like message, telling you what it is: It's floating above the rest of the UI, but gets removed automatically after a very short time, and it seems that if you try to…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
3
votes
1 answer

toast.getView() and toast.setView() is deprecated

I want to show custom toast to users. But toast.getView() and toast.setView() is deprecated in android studio. Here is my code: Toast toast = Toast.makeText(context, "Show Toast", Toast.LENGTH_LONG); View view =…
Md Mahmudul Islam
  • 2,514
  • 4
  • 18
  • 33
3
votes
2 answers

Sometimes Toast doesn't disappear and remains visible even after I terminate App

I have a very simple Toast shown under certain circumstamces: if (!this.isFinishing()) { Toast.makeText(this, R.string.my_toast_message, Toast.LENGTH_LONG).show(); ] Most of the times the Toast is shown and fades away as supposed but sometimes…
AndreaF
  • 11,975
  • 27
  • 102
  • 168
3
votes
0 answers

Android Pie - Toast messages overwriting previous one

Up until Android Pie, when I sent multiple Toast messages sequentially, they were all displayed sequentially. On my API 28 emulator, when I send multiple Toasts at the same time, only the last one is shown. Is this a behavior change across Android…
Florian Walther
  • 6,237
  • 5
  • 46
  • 104
3
votes
3 answers

Android Toast doesn't show up

I am using a Samsung Galaxy Note 8 with Android 8.0. My Toast message (which was working) does not show up Toast.makeText(this, "ABC", Toast.LENGTH_SHORT).show(); getApplicationContext(), getBaseContext() are not helping instead of this. Using…
Damaro
  • 55
  • 1
  • 8
3
votes
3 answers

NullPointerException from Toast while Unit Testing

I am testing a function of my Signup class, however every time I run it a NullPointerException occurs inside the first if statement it enters at: pass.show() I suspect it is has something to do with not testing the app with an emulator. How can I…
Caiz22
  • 697
  • 3
  • 12
  • 21