ReactNative学习----15对话框组件Alert使用

本文介绍了ReactNative中的Alert组件,详细讲解了如何使用官方文档提供的API,并提供了AlertDemo1.js的源码示例,供开发者直接复制使用。通过阅读,开发者可以了解如何在ReactNative应用中实现对话框功能。
摘要由CSDN通过智能技术生成

官方文档
https://reactnative.cn/docs/alert.html#docsNav
源码复制即可使用:
AlertDemo1.js

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,Alert} from 'react-native';

/**
 * 对话框
 * https://reactnative.cn/docs/alert.html#docsNav
 */
export default class AlertDemo1 extends Component{
    constructor(props){
        super(props);
    }
    myClick=()=>{
        Alert.alert(
            'Alert Title',
            'My Alert Msg',
            [
                {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
                {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
                {text: 'OK', onPress: () => console.log('OK Pressed')},
            ],
            { cancelable: false }
        )


    }
    render(){
        return(
            <View>
                <Text style={styles.textStyle} onPress={()=>this.myClick()}>按钮</Text>
            </View>

        );

    }

}

const styles = StyleSheet.create({
    textStyle:{
        backgroundColor:'#3399FF',
        color:'#ffffff',
        marginTop:30,
        width:100,
        height:40,
    }

});




源码下载:
bkdemo1----AlertDemo1
https://download.csdn.net/download/zhaihaohao1/11022393

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值