加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React native 的弹出层组件使用

发布时间:2020-12-15 03:24:53 所属栏目:百科 来源:网络整理
导读:组件名称:Alert、AlertIOS 具体代码如下 /*弹出层测试*/importReact,{Component}from'react';import{StyleSheet,View,Image,Text,TouchableOpacity,ScrollView,Navigator,Alert,//引入Alert组件TouchableHighlight,AlertIOS//引入AlertIOS组件}from'react-n

组件名称:Alert、AlertIOS 具体代码如下

/*弹出层测试*/
importReact,{Component}from'react';
import{
StyleSheet,View,Image,Text,TouchableOpacity,ScrollView,Navigator,Alert,//引入Alert组件
TouchableHighlight,AlertIOS//引入AlertIOS组件
}from'react-native';
//创建一个组件
classCustomButtonextendsComponent{
render(){
return(
<TouchableHighlight
style={styles.button}
underlayColor="red"//触摸的时候颜色改变
onPress={this.props.onPress}>//当前触发时间
<Textstyle={styles.buttonText}>{this.props.text}</Text>
</TouchableHighlight>
);
}
}
//默认输出组件
exportdefaultclassAlertDemoextendsComponent{
render(){
return(
<Viewstyle={styles.container}>
<Textstyle={{height:30,color:'black',margin:8}}>
弹出框实例
</Text>
//触发事件
<CustomButtontext='点击弹出默认Alert'
onPress={()=>Alert.alert('温馨提醒','确定退出吗?')}
/>
<CustomButtontext='点击弹出两个按钮的Alert'
onPress={()=>Alert.alert('温馨提醒','确定退出吗?',[
{text:'取消'},{text:'确定',}
])}
/>
<CustomButtontext='点击弹出三个按钮的Alert'
onPress={()=>AlertIOS.alert('温馨提醒',[
{text:'One'},{text:'Two'},])}
/>
<CustomButtontext='点击出现输入框'
onPress={()=>AlertIOS.prompt('温馨提醒',}
])}
/>

</View>
);
}
}



varstyles=StyleSheet.create({
container:{
backgroundColor:"#fff",flex:1,marginTop:65,},button:{
margin:5,backgroundColor:'white',padding:15,borderBottomWidth:StyleSheet.hairlineWidth,borderBottomColor:'#cdcdcd',}


})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读