Toast

suggest change

Introduction

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

From Android 11, text toasts ignore setGravity.

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents