如何在原生反应中设置警报
问题描述:
如何更改颜色并使我的警报框中的文本居中对待。如何在原生反应中设置警报
这是我的代码。
Alert.alert(
'Edit Profile',
'User Save Succesful!',
[
{text: 'OK', onPress:() => console.log('OK Pressed')},
],
{ cancelable: false }
)
答
您可以使用此库React-Native_DropDown-Alert。其高度可自定义的库,提供不同类型警报的预定义样式。代码将会像这样。
<View>
// !!! Make sure it's the last component in your document tree.
<DropdownAlert
ref={(ref) => this.dropdown = ref}
onClose={(data) => this.onClose(data)} />
</View>
// ...
handleRequestCallback(err, response) {
if (err != null) {
this.dropdown.alertWithType('error', 'Error', err)
}
}
// ...
onClose(data) {
// data = {type, title, message, action}
// action means how the alert was dismissed. returns: automatic, programmatic, tap, pan or cancel
}
// ...
可能重复[我如何设计反应本机的Alert元素?](https://stackoverflow.com/questions/41665902/how-do-i-style-an-alert-element-在反应的天然) –