activeTintColor不更改react-navigation中的Icon Color

问题描述 投票:0回答:2
    HomeStack.navigationOptions = {
    tabBarLabel: 'Home',
    tabBarIcon: ({ focused }) => (
        <TabBarIcon
            focused={focused}
            name={Platform.OS === 'ios' ? 'ios-home' : 'md-home'}

        />
    ),
    tabBarOptions: {
        activeTintColor: '#cd077d',

    },
};

我正在尝试更改我的TabBarIcon的颜色我尝试过ActiveTintColor但这似乎只是改变了文本颜色而不是图标颜色,它当前是活动时的默认蓝色。

reactjs react-native react-navigation
2个回答
1
投票

试试这个

  HomeStack.navigationOptions = {
    tabBarLabel: 'Home',
    tabBarIcon: ({focused, tintColor }) => (
        <TabBarIcon
            focused={focused}
            name={Platform.OS === 'ios' ? 'ios-home' : 'md-home'}
            tintColor={{ tintColor }}

        />
    ),
    tabBarOptions: {
        activeTintColor: '#cd077d',

    },
};

0
投票

你能不能设置返回的TabBarIcon组件的颜色?在官方文档中查看tintColor:https://reactnavigation.org/docs/en/tab-based-navigation.html

    export default createBottomTabNavigator(
  {
    Home: HomeScreen,
    Settings: SettingsScreen,
  },
  {
    defaultNavigationOptions: ({ navigation }) => ({
      tabBarIcon: ({ focused, horizontal, tintColor }) => {
        return <IconComponent name={iconName} size={25} color={tintColor} />;
      },
    }),
    tabBarOptions: {
      activeTintColor: 'tomato',
      inactiveTintColor: 'gray',
    },
  }
);
© www.soinside.com 2019 - 2024. All rights reserved.