ToastAndroid is Android-only. On iOS and other platforms, it has no effect.
The 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
import { ToastAndroid } from 'react-native';
Methods
show()
static show(message: string, duration: number): void
Display a toast notification.
Parameters:
message: Text to display in the toast
duration: Either ToastAndroid.SHORT or ToastAndroid.LONG
Example
import { ToastAndroid } from 'react-native';
ToastAndroid.show('Hello, Android!', ToastAndroid.SHORT);
showWithGravity()
static showWithGravity(
message: string,
duration: number,
gravity: number
): void
Display a toast with custom positioning.
Parameters:
message: Text to display
duration: ToastAndroid.SHORT or ToastAndroid.LONG
gravity: ToastAndroid.TOP, ToastAndroid.BOTTOM, or ToastAndroid.CENTER
On Android R (API 30) or later, gravity settings may not affect toast position for text toasts. This is an Android platform limitation.
Example
import { ToastAndroid } from 'react-native';
ToastAndroid.showWithGravity(
'Toast at the top!',
ToastAndroid.SHORT,
ToastAndroid.TOP
);
showWithGravityAndOffset()
static showWithGravityAndOffset(
message: string,
duration: number,
gravity: number,
xOffset: number,
yOffset: number
): void
Display a toast with custom positioning and pixel offsets.
Parameters:
message: Text to display
duration: ToastAndroid.SHORT or ToastAndroid.LONG
gravity: ToastAndroid.TOP, ToastAndroid.BOTTOM, or ToastAndroid.CENTER
xOffset: Horizontal offset in pixels
yOffset: Vertical offset in pixels
On Android R (API 30) or later, gravity and offset settings may not affect toast position for text toasts.
Example
import { ToastAndroid } from 'react-native';
ToastAndroid.showWithGravityAndOffset(
'Offset toast',
ToastAndroid.LONG,
ToastAndroid.BOTTOM,
25,
50
);
Constants
Duration Constants
ToastAndroid.SHORT // ~2000ms (2 seconds)
ToastAndroid.LONG // ~3500ms (3.5 seconds)
Gravity Constants
ToastAndroid.TOP // Position at top of screen
ToastAndroid.BOTTOM // Position at bottom of screen
ToastAndroid.CENTER // Position at center of screen
Gravity constants may not have visible effects on Android R (API 30) or later when targeting that API level.
Usage Examples
Basic Toast
import React from 'react';
import { Button, ToastAndroid, View } from 'react-native';
function App() {
const showToast = () => {
ToastAndroid.show('A pikachu appeared nearby!', ToastAndroid.SHORT);
};
return (
<View>
<Button title="Show Toast" onPress={showToast} />
</View>
);
}
export default App;
Toast with Gravity
import React from 'react';
import { Button, ToastAndroid, View } from 'react-native';
function App() {
const showToastWithGravity = () => {
ToastAndroid.showWithGravity(
'All Your Base Are Belong To Us',
ToastAndroid.SHORT,
ToastAndroid.CENTER
);
};
return (
<View>
<Button title="Show Centered Toast" onPress={showToastWithGravity} />
</View>
);
}
export default App;
Toast with Offset
import React from 'react';
import { Button, ToastAndroid, View } from 'react-native';
function App() {
const showToastWithOffset = () => {
ToastAndroid.showWithGravityAndOffset(
'A wild toast appeared!',
ToastAndroid.LONG,
ToastAndroid.BOTTOM,
25, // x offset
50 // y offset
);
};
return (
<View>
<Button title="Show Toast with Offset" onPress={showToastWithOffset} />
</View>
);
}
export default App;
import React from 'react';
import { Button, Platform, ToastAndroid, Alert, View } from 'react-native';
function App() {
const showNotification = (message) => {
if (Platform.OS === 'android') {
ToastAndroid.show(message, ToastAndroid.SHORT);
} else {
Alert.alert('Notification', message);
}
};
return (
<View>
<Button
title="Show Notification"
onPress={() => showNotification('Hello!')}
/>
</View>
);
}
export default App;
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
Alert instead.