在Android的底部标签导航中不会显示React Native Vector图标

问题描述

该图标显示在屏幕/页面中,但不会显示底部导航中。我尝试过的解决方案:

  • 遵循github的安装指南,我尝试了 GRADLE MANUAL 选项,但结果相同
  • 曾尝试先./gradlew clean然后npx react-native run-android,但结果相同
  • 曾尝试先npx react-native link react-native-vector-icons 然后npx react-native run-android,但结果相同

屏幕截图底部导航栏

屏幕截图设置屏幕

它确实出现在屏幕/页面中,如上面的屏幕截图所示,但不会显示底部导航中。

注意::我已经在模拟器和真实的android设备上进行了测试,但结果仍然相同!

底部标签代码

import React from 'react'
import { StyleSheet,Text,View } from 'react-native'
import Ionicons from 'react-native-vector-icons/Ionicons'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import ProductNavigation from './ProductNavigation'
import SettingScreen from '../screen/SettingScreen'



const BottomTab = createBottomTabNavigator();

const BottomTabNav = () => {
return (
    <BottomTab.Navigator>
        <BottomTab.Screen 
        name="Home" 
        component={ProductNavigation} 
        options={{
            tabBarLabel: "Home",tabBarIcon:({color,size}) => {
                <Ionicons name="home-outline" color={color} size={size} />
            }}} />

        <BottomTab.Screen 
        name="Settings" 
        component={SettingScreen}
        options={{
            tabBarLabel: "Settings",tabBarIcon: ({color,size}) => {
                <Ionicons name="settings-outline" color={color} size={size} 
    />
            
        }}} />
    </BottomTab.Navigator>
   )
  }

 export default BottomTabNav

 const styles = StyleSheet.create({})

您还能帮忙为什么底部选项卡转到下一页?我应该在哪里编辑代码,在此先感谢。下面是屏幕截图:

enter image description here

解决方法

问题实际上很简单,您没有从函数返回任何信息,

    tabBarIcon: ({color,size}) => {
//nothing returned here
                    <Ionicons name="settings-outline" color={color} size={size} 
        />

您必须执行此操作,或者使用下面的方括号,或者在代码中使用return语句。

tabBarIcon: ({color,size}) => (
                <Ionicons name="settings-outline" color={color} size={size} 
    />)
,

首先,请确保正确使用图标。

例如,假设我们使用MaterialCommunityIcons

import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
const Tab = createBottomTabNavigator();
function MyTabs() {
  return (
    <Tab.Navigator
      initialRouteName="Home"
      tabBarOptions={{
        activeTintColor: '#e91e63',}}
    >
      <Tab.Screen
        name="Home"
        component={Home}
        options={{
          tabBarLabel: 'Home',tabBarIcon: ({ color,size }) => (
            <MaterialCommunityIcons name="home" color={color} size={size} />
          ),}}
      />
      <Tab.Screen
        name="Settings"
        component={Settings}
        options={{
          tabBarLabel: 'Updates',size }) => (
            <MaterialCommunityIcons name="settings" color={color} size={size} />
          ),tabBarBadge: 3,}}
      />
    Tab.Navigator>
  );
}

一般用法是这样的。检查文档以了解详细信息。 https://reactnavigation.org/docs/bottom-tab-navigator/

,

您需要创建一个自定义标签栏组件,并在其中添加图标。 React Navigation有一个很好的文档-https://reactnavigation.org/docs/bottom-tab-navigator#tabbar