版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhaihaohao1/article/details/88632787
官方文档
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