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

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

技术教程推荐

MySQL实战45讲 -〔林晓斌〕

TypeScript开发实战 -〔梁宵〕

To B市场品牌实战课 -〔曹林〕

实用密码学 -〔范学雷〕

Spring编程常见错误50例 -〔傅健〕

Go 语言项目开发实战 -〔孔令飞〕

HarmonyOS快速入门与实战 -〔QCon+案例研习社〕

深入剖析Java新特性 -〔范学雷〕

Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕

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