如何在 react-native 中设置 Alert 元素的样式? [英] how do I style an Alert element in react-native?

查看:36
本文介绍了如何在 react-native 中设置 Alert 元素的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working with react-native and I have created an Alert element.

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

现在我想对它应用一些样式.假设我想为文本应用红色背景颜色和白色背景.

Now I'd like to apply some style to it. Let's say I want to apply to it a red background color and white color for the text.

我怎样才能做到这一点?可能吗?

How can I achieve this? Is it possible?

推荐答案

您可以使用像 react-native-modalbox.

您可以随意设置模态样式:

You'll be able to style the modal as you like:

        <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.教练

Bonus: If you want to find a good library for react-native, try js.coach

这篇关于如何在 react-native 中设置 Alert 元素的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆