reactjs - 如何在react-native中设置Alert元素的样式?

标签 reactjs react-native

我正在使用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/

相关文章:

reactjs - 为什么添加ref到child ref只能获取组件实例而不是DOM节点?

javascript - 当我的 React 组件通过 AJAX 获取时显示加载旋转器/gif 的最佳方式?

javascript - 即使在react中状态为200,也无法在fetch中获取数据

reactjs - 调整大小后获取实际图像大小 React Native

javascript - 对象作为 React Child 无效(找到 : object with keys{id, name})

javascript - 在 React.js 中渲染之前消耗 REST 资源

javascript - typescript 3 : JSX element type 'Component' does not have any construct or call signatures. [2604]

react-native - ScrollView 在 native react 中不滚动

react-native - 如何在为 react-native FlatList getItemLayout 渲染之前获取 View 的大小

javascript - React-Native 博览会 POST Blob