Alert顧名思義一就是一個(gè)警告框,一般使用情況比如:退出登錄,清楚緩存,提示修改密碼等等。。。ReactNative中的Alert只有一個(gè)靜態(tài)方法alert()其中有四個(gè)參數(shù):標(biāo)題,信息,按鈕和按鈕類型 在Android按鈕至多有三個(gè) 下面是使用情況:

實(shí)例代碼:
/** * Created by Administrator on 2016/9/12. */import React, {Component} from 'react';import { StyleSheet, View, Text, Alert,} from 'react-native';class AlertG extends Component { render() { return ( <View style={{flex: 1}}> <Text style={styles.text} onPress={()=> this.showOneAlert()}>One</Text> <Text style={styles.text} onPress={()=> this.showTwoAlert()}>Two</Text> <Text style={styles.text} onPress={()=> this.showThreeAlert()}>Three</Text> </View> ) } showOneAlert() { Alert.alert( 'Alert 標(biāo)題', '只有一個(gè)按鈕', [ /** * 注意參數(shù)名字一定不能錯(cuò) */ {text: '確定', onPress: ()=> console.log('點(diǎn)擊確定')} ]); } showTwoAlert() { Alert.alert( 'Alert 標(biāo)題', '兩個(gè)按鈕', [ {text: '確定', onPress: ()=> console.log('點(diǎn)擊確定')}, {text: '取消', onPress: ()=> console.log('點(diǎn)擊取消')} ] ); } showThreeAlert() { Alert.alert( 'Alert 標(biāo)題', '三個(gè)按鈕', [ //第一個(gè)和第二個(gè)按鈕的位置會顛倒 {text: '取消', onPress: ()=> console.log('點(diǎn)擊取消')}, {text: '確定', onPress: ()=> console.log('點(diǎn)擊確定')}, {text: '稍后', onPress: ()=> console.log('點(diǎn)擊稍后')}, ] ); }}const styles = StyleSheet.create({ text: { fontSize: 28 }})module.exports = AlertG;感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選