如何更改活动/选定标签的颜色?

Joh*_*oah 1 tabnavigator react-native

我希望在未选择选项卡时将颜色设置为默认的灰色,而在选择选项卡时将其设置为我的tabBarColor颜色。我在标签栏中找不到更改标题颜色的方法。

我怎样才能做到这一点?

这是我的代码:

Home:{
  screen: TabNavigator({
   Home: {
    screen: HomeScreen,
    navigationOptions: ({ navigation }) => ({
      title: 'Home',
      tabBarIcon: ({ tintColor, focused }) => (
        <Ionicons
        name={focused ? 'ios-home' : 'ios-home-outline'}
        size={26}
        style={{ color: focused ? `${tabBarColor}` : tintColor}}
        />
      ),
      //headerStyle: {backgroundColor: "#553A91"},
      //headerTitleStyle: {color: "#FFFFFF"},
      header: null,
    }),
  },
  Profile: {
    screen: ProfileScreen,
    navigationOptions: ({ navigation }) => ({
      title: 'Profile',
      tabBarIcon: ({ tintColor, focused }) => (
        <Ionicons
        name={focused ? 'ios-people' : 'ios-people-outline'}
        size={26}
        style={{ color: focused ? `${tabBarColor}` : tintColor }}
        />
      ),
      //headerStyle: {backgroundColor: "#553A91"},
      //headerTitleStyle: {color: "#FFFFFF"},
      header: null,
    }),
  },
}),
}
Run Code Online (Sandbox Code Playgroud)

Kha*_*laf 6

TabNavigator Docs中,明确指出您需要使用activeTintColor

activeTintColor:活动标签的标签和图标颜色

例:

const MyApp = TabNavigator({
  Home: {
    screen: MyHomeScreen,
  },
  Notifications: {
    screen: MyNotificationsScreen,
  },
}, {
  navigationOptions: ({navigation}) => ({
        tabBarIcon: ({focused}) => {
            ...
        }
  }),
  tabBarOptions: {
        activeTintColor: '#ffffff',
  },
});
Run Code Online (Sandbox Code Playgroud)