我正在使用react-native,并且创建了一个警报元素。
Alert.alert(
'Warning',
'bla bla bla',
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
]
)
现在我想对其应用一些样式。假设我想为其应用红色背景颜色和白色文本。
我怎样才能实现这个目标?可能吗?
最佳答案
实际上有一种方法可以自定义按钮上的文本,但您仅限于所提供的内容...下面是来自 React Native 的类型定义。然后是一个显示红色按钮的简单示例。基本上“默认”是蓝色,“取消”是粗体但仍然是蓝色,“破坏性”是红色。
**
* An Alert button style
*/
export type AlertButtonStyle = $Enum<{
/**
* Default button style
*/
'default': string,
/**
* Cancel button style
*/
'cancel': string,
/**
* Destructive button style
*/
'destructive': string,
}>;
Alert.alert("Look out!",
"Hitting reset will wipe all the app's data on your phone. This cannot be undone!",
[
{text: 'Reset', onPress: this._doSomethingSerious, style: 'destructive'},
{text: 'Cancel'},
],
{cancelable: false}
)
关于reactjs - 如何在react-native中设置Alert元素的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41665902/