ToastAndroid
React Native's ToastAndroid API exposes the Android platform's ToastAndroid module as a JS module. It provides the method show(message, duration) which takes the following parameters:
- message A string with the text to toast
- duration The duration of the toastβeither
ToastAndroid.SHORTorToastAndroid.LONG
You can alternatively use showWithGravity(message, duration, gravity) to specify where the toast appears in the screen's layout. May be ToastAndroid.TOP, ToastAndroid.BOTTOM or ToastAndroid.CENTER.
The showWithGravityAndOffset(message, duration, gravity, xOffset, yOffset) method adds the ability to specify an offset with in pixels.
Starting with Android 11 (API level 30), setting the gravity has no effect on text toasts. Read about the changes here.
Reference
Methodsβ
show()β
staticshow(message:string, duration:number);
showWithGravity()β
This property will only work on Android API 29 and below. For similar functionality on higher Android APIs, consider using snackbar or notification.
staticshowWithGravity(message:string, duration:number, gravity:number);
showWithGravityAndOffset()β
This property will only work on Android API 29 and below. For similar functionality on higher Android APIs, consider using snackbar or notification.
staticshowWithGravityAndOffset(
message:string,
duration:number,
gravity:number,
xOffset:number,
yOffset:number,
);
Propertiesβ
SHORTβ
Indicates the duration on the screen.
staticSHORT:number;
LONGβ
Indicates the duration on the screen.
staticLONG:number;
TOPβ
Indicates the position on the screen.
staticTOP:number;
BOTTOMβ
Indicates the position on the screen.
staticBOTTOM:number;
CENTERβ
Indicates the position on the screen.
staticCENTER:number;