小编典典

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

reactjs

我正在使用react-native,并且创建了一个Alert元素。

Alert.alert(
    'Warning',
    'bla bla bla',
    [
           {text: 'OK', onPress: () => console.log('OK Pressed')},
    ]
)

现在,我想对其应用某种样式。假设我要为其应用红色背景色和白色的文本。

我该如何实现?可能吗?


阅读 1096

收藏
2020-07-22

共1个答案

小编典典

您可以使用自定义库,例如react-native-modalbox

您将可以根据需要设置样式的样式:

        <Modal style={{background: 'red'}} ref={"modal1"}>
          <Text style={{color: 'white'}}>Basic modal</Text>
          <Button onPress={this.toggleSwipeToClose} style={styles.btn}>Disable swipeToClose({this.state.swipeToClose ? "true" : "false"})</Button>
        </Modal>

您可以使用打开模态

openModal1(id) {
    this.refs.modal1.open();
  }

查看示例以查看更多选项。

奖励 :如果您想为react-native找到一个好的库,请尝试js.coach

2020-07-22