Skip to content Skip to sidebar Skip to footer

Android Sdk Keep Toast From Fading Away

Quick question: Is there a way to display a toast message that doesn't fade away until I call cancel() on it? I have tried setting the duration to something like 9999 but that does

Solution 1:

Is there a way to display a toast message that doesn't fade away until I call cancel() on it?

No, not directly from the SDK, but you can "tweak" your Toast to make it live longer by calling show() on it as many times you wish using threads. See this article for more information.

Solution 2:

A Toast that doesn't go away until you cancel it is called a Dialog (or AlertDialog). The integer you pass to Toast.setDuration() is a flag - not a value - it will only recognize the values Toast.LENGTH_SHORT and Toast.LENGTH_LONG.

Solution 3:

The Toast calss description says:

"A toast is a view containing a quick little message for the user. The toast class helps you create and show those..."

"...The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved..."

As for the duration parameter it should be one of LENGTH_LONG or LENGTH_SHORT - 1 or 0 respectively.

Use a dialogue that looks like a Toast if you really have to, but I don't recommend doing this because this wont be what a user expects from a Toast.

Solution 4:

Toast Message works with time.there is no way to control it with the cancel.You have to use Dialog for the kind of purpose

Solution 5:

The official doc says (http://developer.android.com/reference/android/widget/Toast.html#makeText(android.content.Context, int, int) ):

publicstatic Toast makeText (Context context, int resId, int duration)

Since: API Level 1
Make a standard toast that just contains a text view with the textfrom a resource.
Parameters

context    The context to use. Usually your Application or Activity object.
resId      The resource id of the string resource to use. Can be formatted text.
duration   How longto display the message. Either LENGTH_SHORT or LENGTH_LONG
Throws     Resources.NotFoundException  if the resource can't be found.

This means there is no direct way to do that. You will have to build your custom code for this. As Toasts exacly overlap each other you can call the same Toast every second with a thread as an example, and use a cancel() custom method to terminate that thread.

Post a Comment for "Android Sdk Keep Toast From Fading Away"