1.创建 drawable-xxhdpi 文件夹,保存 TabBar 的 icon图标

android  --  app  --  src  --  main  --  res  --  drawable-xxhdpi

2.修改后的 Main.js

/**
* 主页面
*/
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
Image,
Platform, //判断当前运行的系统
} from 'react-native'; /*=============导入外部组件类==============*/
import TabNavigator from 'react-native-tab-navigator'; // 引入外部的组件(此处注意是相当于了项目根目录)
var Home = require('../Component/Home');
var Message = require('../Component/Message');
var Find = require('../Component/Find');
var Mine = require('../Component/Mine'); // ES5
var Main = React.createClass({
// 初始化函数(变量是可以改变的,充当状态机的角色)
getInitialState(){
return{
selectedTab:'home' // 默认选中的tabBar
}
}, render() {
return (
<TabNavigator>
{/*--首页--*/}
<TabNavigator.Item
title="首页"
renderIcon={() => <Image source={{uri:"icon_tabbar_home"}} style={styles.iconStyle} />}
renderSelectedIcon={() => <Image source={{uri:"icon_tabbar_home_selected"}} style={styles.iconStyle} />}
selected={this.state.selectedTab === "home"}
onPress={() => this.setState({ selectedTab: "home" })}
selectedTitleStyle={styles.selectedTitleStyle} //tabBarItem选中的文字样式
badgeText="1"
>
<Home />
</TabNavigator.Item> {/*--消息--*/}
<TabNavigator.Item
title="消息"
renderIcon={() => <Image source={{uri:"icon_tabbar_message"}} style={styles.iconStyle} />}
renderSelectedIcon={() => <Image source={{uri:"icon_tabbar_message_selected"}} style={styles.iconStyle} />}
selected={this.state.selectedTab === "message"}
onPress={() => this.setState({ selectedTab: "message" })}
selectedTitleStyle={styles.selectedTitleStyle} //tabBarItem选中的文字样式
badgeText="2"
>
<Message />
</TabNavigator.Item> {/*--发现--*/}
<TabNavigator.Item
title="发现"
renderIcon={() => <Image source={{uri:"icon_tabbar_find"}} style={styles.iconStyle} />}
renderSelectedIcon={() => <Image source={{uri:"icon_tabbar_find_selected"}} style={styles.iconStyle} />}
selected={this.state.selectedTab === "find"}
onPress={() => this.setState({ selectedTab: "find" })}
selectedTitleStyle={styles.selectedTitleStyle} //tabBarItem选中的文字样式
>
<Find />
</TabNavigator.Item> {/*--我的--*/}
<TabNavigator.Item
title="我的"
renderIcon={() => <Image source={{uri:"icon_tabbar_mine"}} style={styles.iconStyle} />}
renderSelectedIcon={() => <Image source={{uri:"icon_tabbar_mine_selected"}} style={styles.iconStyle} />}
selected={this.state.selectedTab === "mine"}
onPress={() => this.setState({ selectedTab: "mine" })}
selectedTitleStyle={styles.selectedTitleStyle} //tabBarItem选中的文字样式
>
<Mine />
</TabNavigator.Item>
</TabNavigator> );
},
}); const styles = StyleSheet.create({
// icon默认样式
iconStyle:{
width: Platform.OS === 'ios' ? 30 : 25,
height:Platform.OS === 'ios' ? 30 : 25,
},
// tabBarItem选中的文字样式
selectedTitleStyle:{
color: 'rgba(212,97,0,1)',
}
}); // 输出
module.exports = Main;

3.效果图

.

react-native 项目实战 -- 新闻客户端(2) -- 完善TabBar的更多相关文章

  1. 【腾讯Bugly干货分享】React Native项目实战总结

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/577e16a7640ad7b4682c64a7 “8小时内拼工作,8小时外拼成长 ...

  2. React Native 项目实战-Tamic

    layout: post title: React Native 项目实战 date: 2016-10-18 15:02:29 +0800 comments: true categories: Rea ...

  3. React Native 项目实战 -- DoubanProject

    引言:本文是我研究react-native时写的一个简单的demo,代码里有详细的注释,好废话不多说,直接上代码. 1.项目目录 2.index.android.js /** * index.andr ...

  4. React Native项目实战

    算是学习React Native的一次项目总结吧,目的还是提高自己. 包含的内容: 1>仿"美团"页面的实现; 2>封装项目中和自己常用的一些组件; 3>学习别人 ...

  5. react-native 项目实战 -- 新闻客户端(6) -- 完善ListView头部视图

    1.因为需要定时器,所以我们要cd到当前项目根目录下安装这个类库: $ npm i react-timer-mixin --save 2.Component/ScrollImage.js /** * ...

  6. react-native 项目实战 -- 新闻客户端(5) -- 完善首页列表数据

    1.Home.js: /** * 首页 */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, T ...

  7. react-native 项目实战 -- 新闻客户端(7) -- 新闻详情页

    http://c.3g.163.com/nc/article/BUH64L0J00031H2L/full.html 观察这个地址,BUH64L0J00031H2L 就是每条新闻数据里的postid.  ...

  8. react-native 项目实战 -- 新闻客户端(4) -- 请求网络数据

    1.Home.js /** * 首页 */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Te ...

  9. react-native 项目实战 -- 新闻客户端(3) -- 包装导航控制器

    1.修改后的 Main.js /** * 主页面 */ import React, { Component } from 'react'; import { StyleSheet, Text, Vie ...

随机推荐

  1. webservice跨域文件,好多年前的东西,远程调用,js服务器端使用,可以远程调用

    1.clientaccesspolicy.xml <?xml version="1.0" encoding="utf-8" ?> <acces ...

  2. 行为型设计模式之中介者模式(Mediator)

    结构 意图 用一个中介对象来封装一系列的对象交互.中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互. 适用性 一组对象以定义良好但是复杂的方式进行通信.产生的相互 ...

  3. luogu 2709 小B的询问 莫队

    题目链接 Description 小B有一个序列,包含\(N\)个\(1-K\)之间的整数.他一共有\(M\)个询问,每个询问给定一个区间\([L..R]\),求\(\sum_{i=1}^{K}c_i ...

  4. 软中断网卡处理&Linux高性能外部设备处理机制&SMP

    转载:http://blog.csdn.net/freas_1990/article/details/9238183 看了一些linux网卡驱动的处理技术,对有些概念还是无法理解,突然搜到这篇文章,挺 ...

  5. Linux内存管理图解【转】

    转自:http://www.360doc.com/content/13/0505/15/12218157_283128759.shtml Linux内存管理图解 2013-05-05  果儿的百科   ...

  6. 阿里云服务器上使用apt-get install出现404 Not Found

    阿里云服务器上使用apt-get install出现404 Not Found 刚申请了的阿里云服务器,在其Ubuntu上用apt-get install安装软件时,会遇到 Failed to fet ...

  7. C#中使用7Z进行压缩解压

    SevenZipSharp相关文档下载地址: http://sevenzipsharp.codeplex.com/releases/view/51254 1. 解决方案中添加引用:SevenZipSh ...

  8. 状压DP【p1879】[USACO06NOV]玉米田Corn Fields

    Description 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上 ...

  9. Shellcode开发辅助工具shellnoob

    Shellcode开发辅助工具shellnoob   Shellcode开发的过程中会遇到很多繁杂的工作,如编译.反编译.调试等.为了减少这部分工作,Kali Linux提供了开发辅助工具shelln ...

  10. 在java代码中设置margin

    我们平常可以直接在xml里设置margin,如: <ImageView android:layout_margin="5dip" android:src="@dra ...