ReactNative Alert詳解及實(shí)例代碼
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;
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
- Reactnative-iOS回調(diào)Javascript的方法
- ReactNative實(shí)現(xiàn)Toast的示例
- ReactNative中使用Redux架構(gòu)總結(jié)
- ReactNative 之FlatList使用及踩坑封裝總結(jié)
- ReactNative Image組件使用詳解
- ReactNative踩坑之配置調(diào)試端口的解決方法
- ReactNative短信驗(yàn)證碼倒計(jì)時(shí)控件的實(shí)現(xiàn)代碼
- ReactNative之鍵盤Keyboard的彈出與消失示例
- ReactNative-JS 調(diào)用原生方法實(shí)例代碼
- ReactNative頁面跳轉(zhuǎn)實(shí)例代碼
- 使用Win10+Android+夜神安卓模擬器,搭建ReactNative開發(fā)環(huán)境
相關(guān)文章
Android實(shí)現(xiàn)軟件列表的點(diǎn)擊啟動另外一個(gè)程序功能【附demo源碼下載】
這篇文章主要介紹了Android實(shí)現(xiàn)軟件列表的點(diǎn)擊啟動另外一個(gè)程序功能,涉及Android針對應(yīng)用程序的讀取、加載、啟動等操作相關(guān)技巧,需要的朋友可以參考下2016-07-07
android AsynTask處理返回?cái)?shù)據(jù)和AsynTask使用get,post請求
本文主要介紹了android AsynTask處理返回?cái)?shù)據(jù)和AsynTask使用get,post請求方法。具有一定的參考價(jià)值,下面跟著小編一起來看下吧2017-01-01
詳解Android中使用OkHttp發(fā)送HTTP的post請求的方法
OkHttp(github.com/square/okhttp)是近來人氣迅速攀升的一款第三方安卓HTTP支持包,這里我們就來詳解Android中使用OkHttp發(fā)送HTTP的post請求的方法2016-07-07
Java實(shí)現(xiàn)Andriod帶看括弧的計(jì)算器代碼
這篇文章主要介紹了Java實(shí)現(xiàn)Andriod帶看括弧的計(jì)算器代碼的相關(guān)資料,需要的朋友可以參考下2016-03-03

