ToastAndroid API exposes the native Android Toast module for displaying short notifications at the bottom of the screen. Toasts automatically disappear after a timeout.
Import
Methods
show()
message: Text to display in the toastduration: EitherToastAndroid.SHORTorToastAndroid.LONG
Example
showWithGravity()
message: Text to displayduration:ToastAndroid.SHORTorToastAndroid.LONGgravity:ToastAndroid.TOP,ToastAndroid.BOTTOM, orToastAndroid.CENTER
Example
showWithGravityAndOffset()
message: Text to displayduration:ToastAndroid.SHORTorToastAndroid.LONGgravity:ToastAndroid.TOP,ToastAndroid.BOTTOM, orToastAndroid.CENTERxOffset: Horizontal offset in pixelsyOffset: Vertical offset in pixels
Example
Constants
Duration Constants
Gravity Constants
Gravity constants may not have visible effects on Android R (API 30) or later when targeting that API level.
Usage Examples
Basic Toast
Toast with Gravity
Toast with Offset
Platform-Specific Toast
Notes
- ToastAndroid only works on Android. On other platforms, calls are ignored.
- Toasts appear above all other app content but below the system status bar.
- Multiple toast calls will be queued and shown sequentially.
- On Android R (API 30+), custom positioning may not work due to platform restrictions.
- Toasts are not interactive and don’t support callbacks.
- For important messages requiring user action, consider using
Alertinstead.