ToastAndroid
React Native 的 ToastAndroid API 将 Android 平台的 ToastAndroid 模块公开为 JS 模块。它提供了方法 show(message, duration),该方法采用以下参数:
¥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 包含要吐司文本的字符串
¥message A string with the text to toast
-
持续时间 Toast 的持续时间 —
ToastAndroid.SHORT或ToastAndroid.LONG¥duration The duration of the toast—either
ToastAndroid.SHORTorToastAndroid.LONG
你也可以使用 showWithGravity(message, duration, gravity) 指定 toast 在屏幕布局中的显示位置。可能是 ToastAndroid.TOP、ToastAndroid.BOTTOM 或 ToastAndroid.CENTER。
¥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.
showWithGravityAndOffset(message, duration, gravity, xOffset, yOffset) 方法添加了以像素为单位指定偏移量的功能。
¥The showWithGravityAndOffset(message, duration, gravity, xOffset, yOffset) method adds the ability to specify an offset with in pixels.
参考
¥Reference
方法
¥Methods
show()
static show(message: string, duration: number);
showWithGravity()
此属性仅适用于 Android API 29 及以下版本。对于更高 Android API 上的类似功能,请考虑使用 snackbar 或通知。
¥This property will only work on Android API 29 and below. For similar functionality on higher Android APIs, consider using snackbar or notification.
static showWithGravity(message: string, duration: number, gravity: number);
showWithGravityAndOffset()
此属性仅适用于 Android API 29 及以下版本。对于更高 Android API 上的类似功能,请考虑使用 snackbar 或通知。
¥This property will only work on Android API 29 and below. For similar functionality on higher Android APIs, consider using snackbar or notification.
static showWithGravityAndOffset(
message: string,
duration: number,
gravity: number,
xOffset: number,
yOffset: number,
);
属性
¥Properties
SHORT
指示屏幕上的持续时间。
¥Indicates the duration on the screen.
static SHORT: number;
LONG
指示屏幕上的持续时间。
¥Indicates the duration on the screen.
static LONG: number;
TOP
指示屏幕上的位置。
¥Indicates the position on the screen.
static TOP: number;
BOTTOM
指示屏幕上的位置。
¥Indicates the position on the screen.
static BOTTOM: number;
CENTER
指示屏幕上的位置。
¥Indicates the position on the screen.
static CENTER: number;