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'>