React Navigation v5中的问号而不是图标

问题描述 投票:0回答:1

我通过以下命令安装了矢量图标:

npm install --save react-native-vector-icons

然后通过这种方法导入图标:(我没有使用expo)

import Ionicons from 'react-native-vector-icons/Ionicons';

这是主要代码:

const MainTab=()=>{

  const Tab = createBottomTabNavigator();

  return(

<Tab.Navigator

screenOptions={({route})=>({
 tabBarIcon:({color, size})=>{
  let iconName;

  if (route.name=='Home') {

    iconName='ios-home'

  }else if(route.name=='Settings'){

  iconName='logo-settings'
 }

 return <Ionicons name={iconName} size={size} color={color} />
 }
})

>


<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Settings" component={SecondPage} />


</Tab.Navigator>
  )}

正在显示问号而不是图标

enter image description here

我该如何解决?

reactjs react-native react-navigation react-native-tabnavigator react-native-vector-icons
1个回答
0
投票

此问题是由于您的图标名称未与库中的图标匹配而引起的。尝试使用不同的图标类型和名称。对于您当前的代码替换iconName='ios-home'iconName='home'iconName='logo-settings'iconName='settings'可能有效。

© www.soinside.com 2019 - 2024. All rights reserved.