ReactNative入门篇之react-native-tab-navigator使用

1、首先安装好ReactNative的运行环境,安装组件依赖库

使用npm install react-native-tab-navigator --save安装所依赖的第三方库

2、导入

import TabNavigator from 'react-native-tab-navigator';

3、使用

               <TabNavigator>
                    <TabNavigator.Item
                        selected={this.state.selectedTab === 'home'}
                        title="业务服务"
                        selectedTitleStyle={{color:"#007aff"}}//设置tab标题颜色
                        renderIcon={() => <Image style={styles.icon} source={require('./res/image/fw1.png')} />}
                        renderSelectedIcon={() => <Image style={[styles.icon,{tintColor:'#007aff'}]} source={require('./res/image/fw2.png')} />}//设置图标选中颜色
                        // badgeText="1"
                        onPress={() => this.setState({ selectedTab: 'home' })}>
                        <View style={styles.pages1}>
                            <Text>这是首页</Text>
                        </View>
                    </TabNavigator.Item>
                    <TabNavigator.Item
                        selected={this.state.selectedTab === 'shebei'}
                        title="设备列表"
                        selectedTitleStyle={{color:"#007aff"}}
                        badgeText="1"
                        renderIcon={() => <Image style={styles.icon} source={require('./res/image/lb1.png')} />}
                        renderSelectedIcon={() => <Image style={[styles.icon,{tintColor:'#007aff'}]} source={require('./res/image/lb2.png')} />}
                        // renderBadge={() => <CustomBadgeView />}
                        onPress={() => this.setState({ selectedTab: 'shebei' })}>
                        <View style={styles.pages2}>
                            <Text>设备列表</Text>
                        </View>
                    </TabNavigator.Item>
                    <TabNavigator.Item
                        selected={this.state.selectedTab === 'hetong'}
                        title="合同管理"
                        selectedTitleStyle={{color:"#007aff"}}
                        renderIcon={() => <Image style={styles.icon} source={require('./res/image/ht1.png')} />}
                        renderSelectedIcon={() => <Image style={[styles.icon,{tintColor:'#007aff'}]} source={require('./res/image/ht2.png')} />}
                        // renderBadge={() => <CustomBadgeView />}
                        onPress={() => this.setState({ selectedTab: 'hetong' })}>
                        <View style={styles.pages3}>
                            <Text>合同管理</Text>
                        </View>
                    </TabNavigator.Item>
                    <TabNavigator.Item
                        selected={this.state.selectedTab === 'qiye'}
                        title="企业信息"
                        selectedTitleStyle={{color:"#007aff"}}
                        renderIcon={() => <Image style={styles.icon} source={require('./res/image/qy1.png')} />}
                        renderSelectedIcon={() => <Image style={[styles.icon,{tintColor:'#007aff'}]} source={require('./res/image/qy2.png')} />}
                        // renderBadge={() => <CustomBadgeView />}
                        onPress={() => this.setState({ selectedTab: 'qiye' })}>
                        <View style={styles.pages4}>
                            <Text>个人中心</Text>
                        </View>
                    </TabNavigator.Item>
                </TabNavigator>

还需要在构造方法中初始化数据,默认让第一个tab选中

    constructor(props) {
        super(props);
        this.state = {selectedTab: "home"}
    }

4、运行结果

运行截图.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,645评论 25 708
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,974评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,009评论 19 139
  • 目标:2.10日前额外收入2W元。 种子实践: 1.上午看见小伙伴们发的昨晚上的咖啡简书,写得太好了,为他们实践种...
    jessie娟子阅读 172评论 0 0
  • 又一个雷雨交加的夜晚,依然能看到车辆和行人穿梭在街道上,马路两边的路灯也孤独的立在那里,微弱的光在雨水的冲刷下显的...
    卢倩851001阅读 192评论 0 0