更改活动TabBarIcon React Native的颜色

时间:2019-11-27 21:17:29

标签: react-native colors expo vector-icons

类似于this question,但我也想更改图标的颜色-不仅是文本。

这是有问题的代码:

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarOptions: {
    activeTintColor: '#6CC7BD',
    inactiveTintColor: '#CCCCCC',
  },
  tabBarIcon: ({focused}) => (
    <TabBarIcon
      focused={focused}
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${focused ? '' : '-outline'}`
          : 'md-information-circle'
      }
    />
  )
}

根据this thread on Github,我应该尝试这样做:

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarOptions: {
    activeTintColor: '#6CC7BD',
    inactiveTintColor: '#CCCCCC',
  },

  tabBarIcon: ({focused}) => <TabBarIcon name={
    Platform.OS === 'ios'
      ? `ios-information-circle${focused ? '' : '-outline'}`
      : 'md-information-circle'
  } color={this.activeTintColor}/>
}

但是信息圈仍然是灰色的: enter image description here

还尝试了color={this.tabBarOptions.activeTintColor},这导致了错误:

enter image description here

还有其他建议吗?

编辑-也尝试过:

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarOptions: {
    activeTintColor: '#6CC7BD',
    inactiveTintColor: '#CCCCCC',
  },
  tabBarIcon: ({activeTintColor}) => (
    <TabBarIcon
      activeTintColor={activeTintColor}
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${activeTintColor ? '' : '-outline'}`
          : 'md-information-circle'
      }
      color={this.activeTintColor}
    />
  )
}

1 个答案:

答案 0 :(得分:1)

您尝试添加所有道具吗?

tabBarIcon: ({focused, ...restProps}) => (
    <TabBarIcon
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${activeTintColor ? '' : '-outline'}`
          : 'md-information-circle'
      }
      focused={focused}
      {...restProps}
    />
  )