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

react-native弹窗Alert

发布时间:2020-12-15 06:25:19 所属栏目:百科 来源:网络整理
导读:学习交流:https://gitee.com/potato512/Learn_ReactNative react-native学习交流QQ群:806870562 效果图 代码示例 import React from 'react';import {View,Text,Button,Alert,AlertIOS} from "react-native";const title = "温馨提示";const message = '要

学习交流:https://gitee.com/potato512/Learn_ReactNative

react-native学习交流QQ群:806870562


效果图


代码示例

import React from 'react';
import {View,Text,Button,Alert,AlertIOS} from "react-native";

const title = "温馨提示";
const message = '要下雨了,记得带伞'

export default class AlertPage extends React.Component {

  constructor(props) {
      super(props);
      _this = this;
      this.state = {
          inputText:'',};
  }

   render(){
     return(
       <View style={{marginTop:60,alignItems:"center"}}>
         <Text>Alert的使用</Text>
         <Button title="标题+确定" onPress={() => {
           Alert.alert(title)
         }}/>
         <Button title="标题+内容+确定" onPress={() => {
           Alert.alert(title,message)
         }}/>
         <Button title="标题+内容+取消+确定" onPress={() => {
           Alert.alert(
            title,message,[
              {text: '不带伞',onPress: () => console.log('Cancel Pressed'),style: 'cancel'},{text: '知道了',onPress: () => console.log('OK Pressed')},],)
         }}/>
         <Button title="标题+内容+多按钮" onPress={() => {
           Alert.alert(
            title,{text: '有人送伞',onPress: () => console.log('送伞')},{
              cancelable: true,onDismiss: () => {
                ToastAndroid.show('点击了外面',ToastAndroid.SHORT)
              }
            }
          )
         }}/>
         <Button title="iOS" onPress={() => {
           AlertIOS.alert(
             title,[
               {text: '取消',onPress: function() {console.log('取消按钮点击');}},{text: '确认',onPress: function() {console.log('确认按钮点击');}},]
           )
         }}/>
         <Button title="iOS+输入框" onPress={() => {
           AlertIOS.prompt(
             title,onPress: (text) => {
                 _this.setState({inputText:text})
                 console.log('你输入了: ' + _this.state.inputText)
               }},'secure-text',this.state.inputText,'number-pad'
           )
         }}/>

)

       </View>
     )
   }
}

(编辑:李大同)

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

    推荐文章
      热点阅读