类似于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}/>
}
还尝试了color={this.tabBarOptions.activeTintColor}
,这导致了错误:
还有其他建议吗?
编辑-也尝试过:
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}
/>
)
}
答案 0 :(得分:1)
您尝试添加所有道具吗?
tabBarIcon: ({focused, ...restProps}) => (
<TabBarIcon
name={
Platform.OS === 'ios'
? `ios-information-circle${activeTintColor ? '' : '-outline'}`
: 'md-information-circle'
}
focused={focused}
{...restProps}
/>
)