欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ReactNative Alert詳解及實例代碼

 更新時間:2016年10月08日 11:13:44   作者:順子_RTFSC  
這篇文章主要介紹了ReactNative Alert詳解及實例代碼的相關資料,需要的朋友可以參考下

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

實例代碼:

/**
 * 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 標題',
      '只有一個按鈕',
      [
        /**
         * 注意參數名字一定不能錯
         */
        {text: '確定', onPress: ()=> console.log('點擊確定')}
      ]);
  }

  showTwoAlert() {
    Alert.alert(
      'Alert 標題',
      '兩個按鈕',
      [
        {text: '確定', onPress: ()=> console.log('點擊確定')},
        {text: '取消', onPress: ()=> console.log('點擊取消')}
      ]
    );
  }

  showThreeAlert() {
    Alert.alert(
      'Alert 標題',
      '三個按鈕',
      [
        //第一個和第二個按鈕的位置會顛倒
        {text: '取消', onPress: ()=> console.log('點擊取消')},
        {text: '確定', onPress: ()=> console.log('點擊確定')},
        {text: '稍后', onPress: ()=> console.log('點擊稍后')},
      ]
    );
  }
}

const styles = StyleSheet.create({
  text: {
    fontSize: 28
  }
})

module.exports = AlertG;

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

最新評論