/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TabBarIOS,
} from 'react-native';
export default class TabBar extends Component {
constructor(pros){
super(pros);
this.state={
//默認(rèn)被選中的Item
selectedTabBarItem:'home'
}
}
render() {
return (
<View style={styles.container}>
{/*頭部*/}
<View>
<Text>TabBar練習(xí)</Text>
</View>
{/*選項(xiàng)卡*/}
<TabBarIOS
barTintColor='black'
tintColor='purple'
>
{/*第一個(gè)*/}
<TabBarIOS.Item
//systemIcon="contacts"
title="首頁(yè)"
badge="3"
selected={this.state.selectedTabBarItem == 'home'}
onPress = {()=>{this.setState({selectedTabBarItem:'home'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'red'}]}>
<Text>首頁(yè)</Text>
</View>
</TabBarIOS.Item>
{/*第二個(gè)*/}
<TabBarIOS.Item
systemIcon="bookmarks"
selected={this.state.selectedTabBarItem == 'second'}
onPress = {()=>{this.setState({selectedTabBarItem:'second'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'green'}]}>
<Text>第二頁(yè)</Text>
</View>
</TabBarIOS.Item>
{/*第三個(gè)*/}
<TabBarIOS.Item
systemIcon="downloads"
selected={this.state.selectedTabBarItem == 'three'}
onPress = {()=>{this.setState({selectedTabBarItem:'three'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'blue'}]}>
<Text>第三個(gè)</Text>
</View>
</TabBarIOS.Item>
{/*第四個(gè)*/}
<TabBarIOS.Item
systemIcon="search"
selected={this.state.selectedTabBarItem == 'four'}
onPress = {()=>{this.setState({selectedTabBarItem:'four'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'purple'}]}>
<Text>第四個(gè)</Text>
</View>
</TabBarIOS.Item>
</TabBarIOS>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
commonViewStyle:{
flex:1,
justifyContent:'center',
alignItems:'center'
}
});
React Native之TabBar基礎(chǔ)使用
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 之前的文章講述了在RN項(xiàng)目中如何使用NavigationBar,如何調(diào)用原生模塊,以及集成下拉刷新和上拉加載更多的...
- 前段時(shí)間搭建項(xiàng)目使用了navigator和react-native-tab-navigator,現(xiàn)在我教大家搭建一...
- React是Facebook開源出來(lái)的一套前段框架,據(jù)目測(cè)是目前最熱門的一套框架,隨之而來(lái)是(RN)React N...
- react-native-storage是封裝好的數(shù)據(jù)存儲(chǔ)組件,安裝方法見:https://github.com/...