在 TabNavigator 中隐藏标签 - ReactNavigation

Hide labels in TabNavigator - ReactNavigation

如何隐藏 TabNavigator 中的标签并仅显示 icons?如果我执行以下操作:

const Tabs = TabNavigator({
  Home: {
    screen:MainHome,
    navigationOptions: ({ navigation }) => ({
        title: "Home",  //Tried to hide this for next tab Search.
        tabBarIcon: ({ tintColor, focused }) => <View><MaterialIcons name="home"/></View>
      })
  },
  Search: {
    screen:TestComp1,
    navigationOptions: ({ navigation }) => ({
      //If no title it shows the name as Search.
      tabBarIcon: ({ tintColor, focused }) => <View><MaterialIcons name="accessibility"/></View>
    })

  }
}, { 

   tabBarPosition: 'bottom',

   tabBarOptions: {
    showIcon: true,
    activeTintColor: '#e91e63',  //Not working for icons.
    inactiveBackgroundColor: 'green', // Not working at all.
    style: {backgroundColor: '#3498DB', height: 60, padding:0, margin:0}
  }
});

如果我从 navigationOptions 中删除 title,它会显示选项卡的名称(HomeSearch)。我只想显示图标并更改活动 icon 的颜色。 activeTintColor 不适用于图标。

TabNavigatorshowLabel 属性可以设置。更多信息请参考docs for v1 or docs for v2.

showIcon - whether to show icon for tab, default is false

showLabel - whether to show label for tab, default is true

这里是显示没有标签的图标的例子。

tabBarOptions: {
  showLabel: false,
  showIcon: true,
  tintColor: '#333',
  activeTintColor: '#aaa',
}

我为更改活动选项卡的标签定义了 tintColor 和 activeTintColor color.for 更改活动选项卡的图标颜色您需要为每个选项卡定义 tabBarIcon 并将 tintColor 传递给它。例如,如果您有一个搜索选项卡,您可以这样做:

Search: {
  screen: SearchScreen,
  navigationOptions:{
    tabBarIcon: ({ tintColor }) => (
      <Icon name="ios-search" style={{color:tintColor}} />
    )
  }
},