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

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

现在我想用一些风格.假设我想为文本应用红色背景色和白色.

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

推荐答案

你可以使用像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();
  }

查看the example查看更多选项.

Bonus:如果你想为react native找到一个好的库,试试js.coach

React-native相关问答推荐

如何在Recact Native中单击Back按钮后调用函数

React Native:任务 ':app:checkDebugDuplicateClasses' 执行失败

ReactNative:在所有组件和操作之间共享 sqlite 实例的最佳方法

react-redux connect 和 redux 数据的组件生命周期顺序

应用程序主体尚未注册

使用 React-Native 将 content:// URI 转换为 Android 的实际路径

react-native 链接仅适用于一个项目(Android 或 iOS)

react-native: 'adb' 不是内部或外部命令、可运行程序或批处理文件

为 React Native TextInput 创建 ref 时出现 TypeScript 问题

使用 Bearer身份验证令牌react native图像

如何渲染多行文本组件,行间有白色间隙

React Native 使视图 Hug键盘顶部

React-native Xcode 构建失败 -> 'RCTAssert.h file not found'

无法在react-native元素中扩展 Zip

如何使 react-native Picker 停留在新 Select 的选项?

React.createClass vs. ES6 箭头函数

由于对 sourcetree 的 husky 预推送,Git 推送失败

WebStorm + ReactNative?

Super expression must either be null or a function, not undefined

无法解析模块react-native-screen