This API is Android-only. It will not work on iOS or other platforms.
This exposes the native ToastAndroid module as a JS module. This has methods to display toast notifications on Android.
Example
Methods
show()
Display a toast message for a specified duration.
Parameters:
Example:
showWithGravity()
Display a toast message for a specified duration with a given gravity.
On Android R (API 30) or later (when targeting API 30+), the gravity setting may not have any effect on text toast placement due to setGravity becoming a no-op.Reference: Android Toast.setGravity documentation
Parameters:
Example:
showWithGravityAndOffset()
Display a toast message for a specified duration with a given gravity and custom offsets. These offset values will translate to pixels.
On Android R (API 30) or later (when targeting API 30+), setting gravity and offsets may not visibly affect the placement of text toasts.
Parameters:
Example:
Constants
Duration Constants
SHORT
Type: number
Value: 2000 (milliseconds / 2 seconds)
Indicates a short duration on the screen.
LONG
Type: number
Value: 3500 (milliseconds / 3.5 seconds)
Indicates a long duration on the screen.
Gravity Constants
On Android R (API 30) or later, these gravity constants may not have any visible effect on toast positioning.
TOP
Type: number
Indicates that the toast message should appear at the top of the screen.
BOTTOM
Type: number
Indicates that the toast message should appear at the bottom of the screen.
CENTER
Type: number
Indicates that the toast message should appear at the center of the screen.
Complete Example