react-native学习(一)————使用react-native-tab-navigator创建底部导航
使用react-native-tab-navigator创建底部Tab导航
1.使用npm安装react-native-tab-navigator
npm install react-native-tab-navigator --save
2.页面引入
import TabNavigator from 'react-native-tab-navigator
3.完整代码
import React, {Component} from 'react';
import { StyleSheet, View, Image} from 'react-native';
import TabNavigator from 'react-native-tab-navigator'
type Props = {};
export default class App extends Component<Props> {
constructor(props){
super(props);
this.state = {
selectedTab: 'tb_popular', // 默认选择第一个
}
}
render() {
return (
//selected:所选tab项指代名称
//selectedTitleStyle:设置选中颜色
//title: tab项展示名称
//renderIcon:默认icon
//renderSelectedIcon :选中icon
//badgeText:徽标数
<TabNavigator>
<TabNavigator.Item
selected = {this.state.selectedTab == 'tb_popular'}
selectedTitleStyle = {{ color: 'red'}}
title = '最热'
renderIcon = { () => <Image style={styles.image} source={require('./res/images/ic_polular.png')} /> }
renderSelectedIcon = { () => <Image style={[styles.image,{tintColor:'red'}]} source = {require('./res/images/ic_polular.png')} />}
badgeText = '1'
onPress = {() => this.setState({ selectedTab: 'tb_popular'})}>
<View style = {styles.page}></View>
</TabNavigator.Item>
<TabNavigator.Item
selected = { this.state.selectedTab == 'tb_trending'}
selectedTitleStyle = {{ color: 'red'}}
title = "趋势"
renderIcon = { () => <Image style={styles.image} source={ require('./res/images/ic_trending.png')}/>}
renderSelectedIcon = { () => <Image style={[styles.image,{tintColor:'red'}]} source = {require('./res/images/ic_trending.png')} />}
onPress = { () => this.setState({ selectedTab: 'tb_trending'})}>
<View style = {styles.page1}></View>
</TabNavigator.Item>
<TabNavigator.Item
selected = {this.state.selectedTab == 'tb_favorite'}
selectedTitleStyle = {{ color: 'red'}}
title = '收藏'
renderIcon = { () => <Image style={styles.image} source={require('./res/images/ic_polular.png')} /> }
renderSelectedIcon = { () => <Image style={[styles.image,{tintColor:'red'}]} source = {require('./res/images/ic_polular.png')} />}
badgeText = '1'
onPress = {() => this.setState({ selectedTab: 'tb_favorite'})}>
<View style = {styles.page}></View>
</TabNavigator.Item>
<TabNavigator.Item
selected = { this.state.selectedTab == 'tb_my'}
selectedTitleStyle = {{ color: 'red'}}
title = "我的"
renderIcon = { () => <Image style={styles.image} source={ require('./res/images/ic_trending.png')}/>}
renderSelectedIcon = { () => <Image style={[styles.image,{tintColor:'red'}]} source = {require('./res/images/ic_trending.png')} />}
onPress = { () => this.setState({ selectedTab: 'tb_my'})}>
<View style = {styles.page1}></View>
</TabNavigator.Item>
</TabNavigator>
);
}
}
const styles = StyleSheet.create({
page:{
flex:1,
backgroundColor:'red',
},
page1:{
flex:1,
backgroundColor:'yellow'
},
image:{
height:22,
width:22
}
});
4.执行结果

react-native学习(一)————使用react-native-tab-navigator创建底部导航的更多相关文章
- (转)2019年 React 新手学习指南 – 从 React 学习线路图说开去
原文:https://www.html.cn/archives/10111 注:本文根据 React 开发者学习线路图(2018) 结构编写了很多新手如何学习 React 的建议.2019 年有标题党 ...
- React+Redux学习笔记:React+Redux简易开发步骤
前言 React+Redux 分为两部分: UI组件:即React组件,也叫用户自定义UI组件,用于渲染DOM 容器组件:即Redux逻辑,处理数据和业务逻辑,支持所有Redux API,参考之前的文 ...
- android布局学习-使用FrameLayout和LinearLayout制作QQ空间底部导航栏
[声明:本博客通过学习“J灬叶小超 ”博客而写,链接:http://www.cnblogs.com/yc-755909659/p/4288260.html] --------------------- ...
- React Native 学习-01
React Native 学习 (学习版本 0.39) 一.环境配置 二.IDE选择 webstorm 1.webstorm配置 ①.首先是可以选择使用汉化包汉化.eu68 ②.安装插件和外部库. 由 ...
- react native 学习一(环境搭配和常见错误的解决)
react native 学习一(环境搭配) 首页,按照http://reactnative.cn/docs/0.30/getting-started.html#content上的介绍,下载安装pyt ...
- React Native学习(三)—— 使用导航器Navigation跳转页面
本文基于React Native 0.52 参考文档https://reactnavigation.org/docs/navigators/navigation-prop 一.基础 1.三种类型 Ta ...
- React Native 学习资料
React Native 学习资料 学习资料 网址 React Native中文网 https://reactnative.cn/
- React Native 学习(三)之 FlexBox 布局
React Native 学习(三)之 FlexBox 布局
- React Native 学习笔记--进阶(二)--动画
React Native 进阶(二)–动画 动画 流畅.有意义的动画对于移动应用用户体验来说是非常必要的.我们可以联合使用两个互补的系统:用于全局的布局动画LayoutAnimation,和用于创建更 ...
随机推荐
- 前端-使用template-web.js【模版引擎】渲染数据
通过ajax请求到的数据,使用传统的拼接字符串也可以做到,但是‘ “ ” ‘这种模式,单引号.双引号容易 扩错,新手入门推荐使用这种,初入前端,需要一个一个敲代码体会一下. 使用 template.j ...
- controler--application配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- SpringBoot编程思想
Spring Boot的特性 1).创建独立的Spring应用 2).直接嵌入Tomcat.Jetty或Undertow等Web容器(不需要部署WAR文件) 3).提供固化的starter依赖,简化构 ...
- 基于SSM的RBAC权限系统(1)-利用ajax,bootstrap,ztree完成权限树功能
仅支持回显以及选择,不支持在树中的编辑 搭建后台回显以及修改的模块 JSON数据封装 public class Msg { private int code; private String msg; ...
- cannot access Input/output error
ls: cannot access Input/output errorls: cannot open directory .: Input/output error 硬盘故障,只读或只写,你可以d ...
- APIO2019 练习赛 Wedding cake——思路+高精度
题目大意: 给 n ( n<=1e5 ) 个数 \( a_i \) (\( a_i \) <=1e5),需要构造 n 个实数使得它们的和是 1 ,并且第 i 个实数必须小数点后恰好有 \( ...
- Linux 虚拟机通过NAT模式访问外网
1.配置本地VM8地址 2.配置虚拟机NAT网卡:设置VM8网卡地址和Linux主机相同网段地址,网关随便设置 3.编译网卡文件 vim /etc/sysconfig/network-scri ...
- Java JsonPath grab InvalidPathException in code, you must be catching Java 7's java.nio.file.InvalidPathException instead of JsonPath's com.jayway.jsonpath.InvalidPathExceptio
I am using JsonPath and am able to parse my data and get the values when the path provided is correc ...
- rm -rf无法删除文件解决方法
# 列出 file.sh 文件的属性 lsattr file.sh # 列出当前目录下所有文件以及文件夹的属性 lsattr # 为 file.sh 文件增加 i 标识 chattr +i file. ...
- Asp.Net Core 第07局:路由
总目录 前言 本文介绍Asp.Net Core 路由. 环境 1.Visual Studio 2017 2.Asp.Net Core 2.2 开局 第一手:路由概述 1.路由主要用于处理特定的请求. ...