react-native-Alert
Posted time_iter
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react-native-Alert相关的知识,希望对你有一定的参考价值。
Alert:
弹出框,安卓平台最多只能指定三个“button”,有三种状态:中间态,确定,取消
一:
import React, Component from 'react';
import
AppRegistry,
View,
TouchableHighlight,
Text,
StyleSheet,
Toastandroid,
Alert,
from 'react-native';
class FristProject extends Component
render()
return (
<View>
<CustonButton text="只有一个按钮"
onPress=()=>Alert.alert("title提示文字","Message")/>
<CustonButton text="两个按钮"
onPress=()=>Alert.alert("title提示文字",'Message',[text:'取消',onPress:()=>ToastAndroid.show("取消",ToastAndroid.SHORT),
text:'确定',onPress:()=>ToastAndroid.show("确定",ToastAndroid.LONG)
])
/>
<CustonButton text='三个按钮'
onPress=()=>Alert.alert("title提示文字","Message",[text:'中间态',onPress:()=>ToastAndroid.show("中间态",ToastAndroid.LONG),text:'确定',onPress:()=>ToastAndroid.show("确定",ToastAndroid.LONG),text:'取消',onPress:()=>ToastAndroid.show("取消",ToastAndroid.LONG)])
></CustonButton>
</View>
);
class CustonButton extends Component
render()
return (
<TouchableHighlight
style=styles.button
underlayColor='#a5a5a5'
onPress=this.props.onPress>
<Text> this.props.text </Text>
</TouchableHighlight>
);
var styles = StyleSheet.create(
button:
margin: 5,
backgroundColor: 'white',
padding: 15,
borderBottomColor: '#cdcdcd'
)
注意点:
-1:若是只指定一个按钮,那么该为’positive’<‘yes||no'>
-2:若是只指定两个个按钮,那么该为’positive’,’negative’<‘yes&&no'>
-3:若是只指定三个按钮,那么该为’positive’,’negative’,’neutral'<‘yes&&no&&cancel'>
以上是关于react-native-Alert的主要内容,如果未能解决你的问题,请参考以下文章