我有一个 tabBar 导航器,我想用图像替换图标,它可以工作,但是 activeTintColor 在聚焦时不会改变,尽管它是在 navigationOptions 中设置的,这里是代码:
TabBarIcon组件
export default class TabBarIcon extends React.Component {
render() {
return (
<Image
source={this.props.source}
tintColor={this.props.focused ? Colors.tabIconSelected : Colors.tabIconDefault}
/>
);
}
}
tabBarNavigator 中的图标
tabBarIcon: ({ focused, tintColor }) => (
<Image
focused={focused}
source={require('/assets/images/icon.png')}
tintColor={tintColor}
/>
),
最佳答案
对于图像,尝试这样设置
tabBarNavigator 中的图标
tabBarIcon: ({ focused }) => {
const image = focused
? require('./image/HomeActive.png')
: require('./image/HomeInactive.png')
return (
<Image
source={image}
style={{height:36, width:24}}
/>
)
}
并在tabBarOptions
下设置activeTintColor和inactiveTintColor
关于javascript - 标签栏导航器中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53964144/