我幾乎從TabNavigator文檔中獲取示例代碼,並且圖標的/圖像不會顯示在iOS或Android上。即使標籤覆蓋似乎也不會生效。我究竟做錯了什麼?圖標/圖像在React Native中不顯示TabBarBottom
這裏的鏈接來我一直在使用的文檔: https://reactnavigation.org/docs/navigators/tab
這裏是我的代碼:
class MyHomeScreen extends React.Component {
static navigationOptions = {
tabBarLabel: 'Not displayed',
// Note: By default the icon is only shown on iOS. Search the showIcon option below.
tabBarIcon: ({ tintColor }) => (
<Image
source={require('./chats-icon.png')}
style={[styles.icon, {tintColor: tintColor}]}
/>
),
};
render() {
return (
<Button
onPress={() => this.props.navigation.navigate('Notifications')}
title="Go to notifications"
/>
);
}
}
class MyNotificationsScreen extends React.Component {
static navigationOptions = {
tabBarLabel: 'Notifications',
tabBarIcon: ({ tintColor }) => (
<Image
source={require('./notif-icon.png')}
style={[styles.icon, {tintColor: tintColor}]}
/>
),
};
render() {
return (
<Button
onPress={() => this.props.navigation.goBack()}
title="Go back home"
/>
);
}
}
const styles = StyleSheet.create({
icon: {
width: 26,
height: 26,
},
});
const MyApp = TabNavigator({
Displayed: {
screen: MyHomeScreen,
},
Notifications: {
screen: MyNotificationsScreen,
},
}, {
tabBarOptions: {
activeTintColor: '#e91e63',
},
});
你確定在'styles.icon'中設置了'width'和'height'嗎? –
@ViktorSeč是的,它就在那裏的樣式sheet.create代碼。 – theHarvester