美文网首页
1.3 底部导航

1.3 底部导航

作者: 倪灏 | 来源:发表于2017-06-21 17:40 被阅读0次

自己做项目中的重点知识,不是教程,如果学习的话可以拿来参考。源代码[地址][2]
[2]: https://github.com/BaiPeiHe/react-native
底部导航菜单
react-native-tab-navigator 地址

1、导入框架:

// 在根目录下执行
npm install react-native-tab-navigator --save

2、添加代码

// 导入框架
import TabNavigator from 'react-native-tab-navigator';

// 代码实现
export default class rn_demo extends Component {
    // 构造函数
    constructor(props){
        super(props);
        this.state={
        // 默认选中
            selectedTab: 'tb_popular',
        }
    }

    // 视图
    render() {
      return (
        <View style={styles.container}>
          <TabNavigator>
              <TabNavigator.Item
                  selected={this.state.selectedTab === 'tb_popular'}
                  selectedTitleStyle={{color:'red'}}
                  title="最热"
                  renderIcon={() => <Image style={styles.iconImage} source={require('./res/images/ic_polular.png')} />}
                  renderSelectedIcon={() => <Image style={[styles.iconImage,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                  badgeText="1"
                  onPress={() => this.setState({ selectedTab: 'tb_popular' })}>
                  <View style={styles.page1}></View>
              </TabNavigator.Item>
              <TabNavigator.Item
                  selected={this.state.selectedTab === 'tb_trending'}
                  selectedTitleStyle={{color:'red'}}
                  title="趋势"
                  renderIcon={() => <Image style={styles.iconImage} source={require('./res/images/ic_trending.png')} />}
                  renderSelectedIcon={() => <Image style={[styles.iconImage,{tintColor:'red'}]} source={require('./res/images/ic_trending.png')} />}
                  onPress={() => this.setState({ selectedTab: 'tb_trending' })}>
                  <View style={styles.page2}></View>
              </TabNavigator.Item>
              <TabNavigator.Item
                  selected={this.state.selectedTab === 'tb_favorite'}
                  selectedTitleStyle={{color:'red'}}
                  title="收藏"
                  renderIcon={() => <Image style={styles.iconImage} source={require('./res/images/ic_polular.png')} />}
                  renderSelectedIcon={() => <Image style={[styles.iconImage,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                  badgeText="1"
                  onPress={() => this.setState({ selectedTab: 'tb_favorite' })}>
                  <View style={styles.page1}></View>
              </TabNavigator.Item>
              <TabNavigator.Item
                  selected={this.state.selectedTab === 'tb_my'}
                  selectedTitleStyle={{color:'red'}}
                  title="我的"
                  renderIcon={() => <Image style={styles.iconImage} source={require('./res/images/ic_trending.png')} />}
                  renderSelectedIcon={() => <Image style={[styles.iconImage,{tintColor:'red'}]} source={require('./res/images/ic_trending.png')} />}
                  onPress={() => this.setState({ selectedTab: 'tb_my' })}>
                  <View style={styles.page2}></View>
              </TabNavigator.Item>
          </TabNavigator>
        </View>
      );
    }
}

const styles = StyleSheet.create({
    container:{
        flex:1,
        backgroundColor: '#F5FCFF',
    },

    page1:{
        flex:1,
        backgroundColor:'red',
    },

    page2:{
        flex:1,
        backgroundColor:'yellow',
    },

    iconImage:{
        height:22,
        width:22
    }
});

注意:
1、导入的图片1-3倍的都要有,引用正常尺寸的图片,rn 会自动的适配2倍和3倍的图片
2、react-native 中尺寸是与设备无关的,所以尺寸没有单位

相关文章

  • 1.3 底部导航

    自己做项目中的重点知识,不是教程,如果学习的话可以拿来参考。源代码[地址][2][2]: https://gith...

  • BottomNavigationView的属性设置

    底部导航栏 底部导航栏的使用比较常见,目前常用的APP几乎都是使用底部导航栏将内容分类。底部导航栏的实现也比较简单...

  • vuejs2项目开发实战视频教程

    0.课程大纲 一、点餐系统(移动) 1.0.课件 1.1.项目初始化_首页顶部 1.2.首页列表_底部导航 1.3...

  • Android使用底部导航2018-08-16

    Android使用底部导航 Android底部导航停留在屏幕底部,提供应用中顶级视图之间的导航。这是在具有向后兼容...

  • 有一种看似多余的导航你知道吗?

    很多网站在页面底部也有导航,这种底部导航看似有些多余。但是他们的作用不比主导航差。 底部导航的作用和做法有如下几种...

  • 为什么底部导航被人忽视

    很多网站在页面底部也有导航,这种底部导航看似有些多余。但是他们的作用不比主导航差。 底部导航的作用和做法有如下几种...

  • 底部导航思路

    底部导航是每个 app 必备的,有的 app 底部导航做的很精美,很有诱人,于是我去特意看看底部导航都有那些玩法 ...

  • 移动端交互之导航

    讨论两种导航架构在应用中的区分:底部横向导航和侧边纵向导航 1、底部横向导航 特点:横向排列与界面底部,可直接方便...

  • 使用 TabLayout 制作底部导航栏

    国内大部分应用使用底部导航栏, 底部导航栏 是国内 APP 常见的导航方式, 历经: TabActivity -...

  • 安卓底部导航

    Android底部导航栏实现(一)之BottomNavigationBarAndroid底部导航栏实现(二)之Ra...

网友评论

      本文标题:1.3 底部导航

      本文链接:https://www.haomeiwen.com/subject/jeytcxtx.html