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
-3
votes
1 answer

Why Toast is not compatible with Android 28+?

why does standard form Toast (also in current google android online docs) give "false caller" error for an app in Android compileSdkVersion/targetSdkVersion 28. Using getApplicationContext() does not matter. public class MainActivity extends…
Goofyseeker311
  • 113
  • 1
  • 3
-3
votes
1 answer

Toast message doesn't show up on actual phone while it shows in emulator

I'm trying to create an android application. One part is to make sure that toast message shows. It works when I'm running the app on the android studio emulator, but it doesn't show when I'm running on actual Samsung phone It's about a thousand line…
Mr.B
  • 29
  • 5
-3
votes
1 answer

Toast setGravity(int i,int xOffset,int yOffset)

what is x-offset and y-offset in setGravity? what is the maximum value for it?
-3
votes
1 answer

Android Studio: I am trying to wire a button to a toast but there is an error with the callback method

package com.example.chris.helloworld; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle…
-3
votes
1 answer

Snackbar shown along with Toast

I am using Google's design support library to show Snackbars. After I compile the apk and run it on phone (Nexus 5), the Snackbar is shown along with the Toast. Running directly from Android Studio works fine (only Snackbar is shown). Any help will…
-3
votes
7 answers

Toast Message not working android

I have 2 classes BlockIdActivity.java and ScanWifi.java. I have 2 buttons in BlockIdActivity.java file and i am able to see my toast defined there. However i cant see the toast for the button i defined in ScanWifi.Java class. Following is the code…
srai
  • 1,023
  • 2
  • 14
  • 27
-3
votes
2 answers

How to show error message without using Toast

Can I show any other way to error message not using toast message. Please help me? and i don't want to display the popup also..
Slaver
  • 3
  • 3
-3
votes
4 answers

Android-Toast: Unable to Toast average of RatingBars

I'm trying to show average of 3 ratingBars using Toast but it always show 0.0. I also tried to convert the average to String but no luck. Please help. Here is my code: float rating1 = ratingBar.getRating(); float rating2 =…
GSng
  • 1
  • 3
-3
votes
4 answers

toast in Java, need to show the value of a textview

i have a resulttextview that shows the result of a computation. I would like to pass the value of the this resulttextview so that it will show in a toast. i have this code: Toast.makeText(MyCalcActivity.this,message,…
Zu5ar
  • 17
  • 1
  • 4
-4
votes
1 answer

Disable Toast on Android

I have added a library, It is showing a toast message every time the app start. How to disable this toast. Any hack method also be appreciated. I am unable to modify library code it is a classpath dependency
sum20156
  • 646
  • 1
  • 7
  • 19
-4
votes
2 answers

I want to Toast will show after multiple clicks

I want to implant toast messages on click but it should show after multiple clicks like we do click on build number 7 times to enable developer option. I mean toast message should show only after multiple clicks like when we click 3,4 or 5…
-4
votes
1 answer

Custom toast for application

I need to create custom Toast like component. This should appears over only my application to show some message. Why i don't use android Toast - because i need custom duration. Problem is I'm creating view through WindowManager.addView with type…
-4
votes
1 answer

What is the range of the x,y Offset of the Toast.setGravity?

I am testing a code where i want some toast text to appear randomly allover the phone screen. What is the max value the x and y offset of a Toast Gravity? int i=0; while(i < 100){ Random rand = new Random(); int xOffset = rand.nextInt(500);…
David Elmasllari
  • 169
  • 1
  • 10
-4
votes
3 answers

How to change android toast to snackbar

I am using a android toast message to display a message to the user but the duration even when set to _LENGTH_LONG seems not enough. I would like to try a SnackBar or any other display method but i am stuck. How can i apply that? This is my code. …
-4
votes
1 answer

App crashing instead of showing toast of empty EditText

If user enters nothing and click on the ok button, the app should show a toast of enter something. But when I start app and click on the ok button without entering, the app crashes showing this error: 09-30 05:06:59.099: E/AndroidRuntime(1656):…
utkarsh dubey
  • 141
  • 2
  • 14
1 2 3
42
43