React Native - 提示框(Alert)

React Native - 提示框(Alert) 首页 / React Native入门教程 / React Native - 提示框(Alert)

在本章中,我们将了解如何创建自定义 Alert 组件。

步骤1 - App.js代码

import React from 'react'
import AlertExample from './alert_example.js'

const App=() => {
   return (
      <AlertExample />
   )
}
export default App

步骤2 - alert_example.js代码

我们将创建一个用于触发 showAlert 函数的按钮。

import React from 'react'
import { Alert, Text, TouchableOpacity, StyleSheet } from 'react-native'

const AlertExample=() => {
   const showAlert=() =>{
      Alert.alert(
         'You need to...'
      )
   }
   return (
      <TouchableOpacity onPress={showAlert} style={styles.button}>
         <Text>Alert</Text>
      </TouchableOpacity>
   )
}
export default AlertExample

const styles=StyleSheet.create ({
   button: {
      backgroundColor: '#4ba37b',
      width: 100,
      borderRadius: 50,
      alignItems: 'center',
      marginTop: 100
   }
})
React Native Alert

当您单击按钮时,您将看到以下内容-

无涯教程网

React Native Alert Button

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

赵成的运维体系管理课 -〔赵成〕

从0开始学架构 -〔李运华〕

Go语言核心36讲 -〔郝林〕

代码精进之路 -〔范学雷〕

从0打造音视频直播系统 -〔李超〕

分布式协议与算法实战 -〔韩健〕

A/B测试从0到1 -〔张博伟〕

React Hooks 核心原理与实战 -〔王沛〕

计算机基础实战课 -〔彭东〕

好记忆不如烂笔头。留下您的足迹吧 :)