React Native之TabBar的簡(jiǎn)單搭建

先上效果動(dòng)態(tài)圖

Untitled.gif

代碼附上:

/**
 * 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';

var test5 = React.createClass({
  
  //設(shè)置初始值
  getInitialState(){
    return{
      //默認(rèn)選擇的item
    selectTabBarItem:'home',
    }
  },
  
  
  render() {
    return (
            <View style={styles.container}>
            <View style={styles.headStyle}>
            <Text style={{color:'white'}}>Tab選項(xiàng)卡</Text>
            </View>
            
            
            <TabBarIOS
            barTintColor='black'
            //tintColor='purple'
            >
            
            {/*第一*/}
            <TabBarIOS.Item
            systemIcon="contacts"
            badge="3"
            title="張三"
            selected={this.state.selectTabBarItem == 'home'}
            onPress = {()=>{this.setState({selectTabBarItem:'home'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'red'}] }>
            <Text style={{color:'white'}}>首頁(yè)</Text>
            </View>
            
            </TabBarIOS.Item>
            
            
            
            {/*第2*/}
            <TabBarIOS.Item
            systemIcon="bookmarks"
            selected={this.state.selectTabBarItem == 'second'}
            onPress = {()=>{this.setState({selectTabBarItem:'second'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'blue'}]}>
            <Text style={{color:'white'}}>2頁(yè)</Text>
            </View>
            </TabBarIOS.Item>
            
            
            {/*第3*/}
            <TabBarIOS.Item
            systemIcon="downloads"
            selected={this.state.selectTabBarItem == 'three'}
            onPress = {()=>{this.setState({selectTabBarItem:'three'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'yellow'}]}>
            <Text style={{color:'white'}}>3頁(yè)</Text>
            </View>
            </TabBarIOS.Item>
            
            
            {/*第4*/}
            <TabBarIOS.Item
            systemIcon="search"
            selected={this.state.selectTabBarItem == 'four'}
            onPress = {()=>{this.setState({selectTabBarItem:'four'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'purple'}]}>
            <Text style={{color:'white'}}>4頁(yè)</Text>
            </View>
            </TabBarIOS.Item>
            
            
            </TabBarIOS>
            
            </View>
            );
  }
})

const styles = StyleSheet.create({
container: {
  
flex:1,
  
backgroundColor: '#F5FCFF',
},
headStyle:{
height:64,
backgroundColor:'black',
justifyContent:'center',
alignItems:'center'
},
commonViewStyle:{
flex:1,
justifyContent:'center',
alignItems:'center'
  
}
  
});

AppRegistry.registerComponent('test5', () => test5);
最后編輯于
?著作權(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)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本篇教程基于NexT主題的博客配置,實(shí)現(xiàn)更換主題、評(píng)論、打賞等36項(xiàng)功能,接下來(lái)根據(jù)這些功能進(jìn)行分點(diǎn)描述,附上個(gè)人...
    wangwlj閱讀 2,381評(píng)論 0 11
  • 前言 學(xué)習(xí)本系列內(nèi)容需要具備一定 HTML 開(kāi)發(fā)基礎(chǔ),沒(méi)有基礎(chǔ)的朋友可以先轉(zhuǎn)至 HTML快速入門(mén)(一) 學(xué)習(xí) 本人...
    珍此良辰閱讀 2,406評(píng)論 3 9
  • 1、工作 照例周三下午是設(shè)計(jì)討論會(huì),今天梁老師所說(shuō)的觀點(diǎn)我很是贊同,也期待自己在這方面做到更好?,F(xiàn)在我們確實(shí)是會(huì)做...
    Coral梁閱讀 305評(píng)論 0 0
  • 晚上用吹風(fēng)機(jī)吹頭發(fā) 結(jié)果付完錢(qián)吹風(fēng)機(jī)卻不運(yùn)作 不僅沒(méi)吹成頭發(fā)還丟了一塊錢(qián) 越想越生氣 資本家休想從我這里掏走一分錢(qián)...
    愛(ài)聽(tīng)故事的巫婆閱讀 259評(píng)論 0 0
  • 一塊豬肉一塊屏, 5 G 創(chuàng)投打頭陣。 大麻醉人垃圾舞, 越說(shuō)沒(méi)有越來(lái)神。 人民網(wǎng)上看大戲, 粘上券商有葷吃。 次...
    鴻運(yùn)_97d7閱讀 244評(píng)論 1 8

友情鏈接更多精彩內(nèi)容