Toast
suggest changeIntroduction
A Toast provides simple feedback about an operation in a small popup and automatically disappears after a timeout. It only fills the amount of space required for the message and the current activity remains visible and interactive.
Syntax
- Toast makeText (Context context,
CharSequence text,
int duration)
- Toast makeText (Context context,
int resId,
int duration)
- void setGravity(int gravity, int xOffset, int yOffset)
- void show()
Parameters
Parameter | Details |
—— | —— |
context | The context to display your Toast in. this
is commonly used in an Activity and getActivity()
is commonly used in a Fragment |
text | A CharSequence that specifies what text will be shown in the Toast. Any object that implements CharSequence can be used, including a String |
resId | A resource ID that can be used to provide a resource String to display in the Toast |
duration | Integer flag representing how long the Toast will show. Options are Toast.LENGTH_SHORT
and Toast.LENGTH_LONG
| gravity | Integer specifying the position, or “gravity” of the Toast. See options here |
xOffset | Specifies the horizontal offset for the Toast position |
yOffset | Specifies the vertical offset for the Toast position |
Remarks
A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive.
A more recent alternative to Toast is SnackBar. SnackBar offers an updated visual style and allows the user to dismiss the message or take further action. See the SnackBar documentation for details.
Official Documentation:
https://developer.android.com/reference/android/widget/Toast.html