ReactNative Alert详解及实例代码
作者:顺子_RTFSC 时间:2022-07-04 15:02:46
Alert顾名思义一就是一个警告框,一般使用情况比如:退出登录,清楚缓存,提示修改密码等等。。。ReactNative中的Alert只有一个静态方法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;
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
标签:ReactNative,Alert
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Mybatis批量插入Oracle数据的方法实例
2021-05-24 23:32:31
Java去重排序之Comparable与Comparator的使用及说明
2023-04-28 00:49:27
![](https://img.aspxhome.com/file/2023/8/122278_0s.png)
Unity实现枚举类型中文显示
2023-02-22 12:00:28
![](https://img.aspxhome.com/file/2023/1/100151_0s.gif)
Android Selector和Shape的使用方法
2022-08-05 23:48:38
![](https://img.aspxhome.com/file/2023/7/106057_0s.gif)
C#实现QQ聊天窗口
2023-07-06 02:43:56
C# using三种使用方法
2023-05-02 20:18:47
Java 全面系统介绍反射的运用
2021-12-18 22:51:30
![](https://img.aspxhome.com/file/2023/3/121943_0s.png)
Android 双击Back键退出应用的实现方法
2023-07-06 05:41:41
C#使用LINQ查询表达式的基本子句总结
2022-08-05 05:09:41
![](https://img.aspxhome.com/file/2023/3/77253_0s.png)
Android音视频开发之MediaExtactor使用教程
2023-03-20 19:25:11
SpringBoot参数校验Validator框架详解
2023-09-22 07:08:40
Java Stream流的常见生成和操作方法总结
2023-08-26 12:06:21
C# 如何使用ajax请求
2023-07-21 07:44:40
C# 实现Table的Merge,Copy和Clone
2021-07-03 02:24:58
Feign如何实现第三方的HTTP请求
2023-06-10 16:20:20
![](https://img.aspxhome.com/file/2023/1/119141_0s.jpg)
Android WebView实现网页滚动截图
2022-12-12 12:13:03
![](https://img.aspxhome.com/file/2023/8/88098_0s.jpg)
详解java倒计时三种简单实现方式
2023-11-11 16:47:38
![](https://img.aspxhome.com/file/2023/8/62508_0s.png)
Android 使用Vitamio打造自己的万能播放器(10)—— 本地播放 (缩略图、视频信息、视频扫描服务)
2023-07-11 08:48:22
![](https://img.aspxhome.com/file/2023/1/126791_0s.png)
c#网络唤醒功能实现
2022-07-03 03:26:51
![](https://img.aspxhome.com/file/2023/3/84443_0s.jpg)
Android仿微信朋友圈实现滚动条下拉反弹效果
2023-02-21 15:48:58
![](https://img.aspxhome.com/file/2023/7/110727_0s.gif)