我有问题使用createBottomTabNavigator
显示图标。我正在使用react-native-ionicons,如果我在代码中放置任何类型的Icon,但它没有显示在标签栏上,它可以正常工作。我已经设置了showIcon: true
。
这是我正在尝试的代码:
import React from 'react';
import {View, Text} from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
import HomeScreen from './screens/HomepageScreen';
class SettingsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
}
const BottomNavigation = createBottomTabNavigator(
{
Home: HomeScreen,
Settings: SettingsScreen,
},
{
tabBarOptions: {
inactiveTintColor: 'gray',
swipeEnabled: true,
showLabel: true,
showIcon: true
},
}
);
export default createAppContainer(BottomNavigation);
在哪里HomepageScreen.js:
import React from 'react';
import {View, Text, Image, ScrollView} from 'react-native';
import {Card, CardItem, Right, Left} from 'native-base';
import {Header} from 'react-native-elements';
import Icon from 'react-native-ionicons'
class HomeScreen extends React.Component {
state = {
news: []
}
static navigationOptions = {
title: 'Noticias',
tabBarIcon: ({tintColor}) => {
<Icon style={{width: 10, height: 10, color: 'black'}} ios="ios-add" android="md-add" />
}
}
render() {
return (
//code
);
}
}
export default HomeScreen;
我错过了什么吗?
大小可能太小了,如果你打算使用color={tintColor}
你需要放tintColor
import React from 'react';
import {View, Text, Image, ScrollView} from 'react-native';
import {Card, CardItem, Right, Left} from 'native-base';
import {Header} from 'react-native-elements';
import Icon from 'react-native-ionicons'
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Noticias',
tabBarIcon: ({tintColor}) => {
<Icon color={tintColor} ios="ios-add" android="md-add" />
}
}
render() {
return (
//code
);
}
}
export default HomeScreen;
希望能帮助到你!