You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native底部导航图标加载失败:Material Design Icons未加载求助

解决React Native底部导航图标加载失败(fontFamily未加载)的问题

先看你代码里的明显错误:导入语句写的是MateriaCommunityIcons,少了个字母'l',正确的应该是MaterialCommunityIcons——这应该是你误改导致的核心问题,先把这个拼写修正。

如果改完拼写还是不行,按下面的步骤排查:

  • 重新执行字体链接并清理缓存

    1. 运行命令重新链接字体:npx react-native link react-native-vector-icons
    2. 清理项目缓存:npx react-native start --reset-cache
    3. 重启模拟器/真机,重新编译整个项目
  • iOS手动补全配置(自动链接失效时)

    1. 打开iOS项目的Info.plist文件,添加以下内容:
    <key>UIAppFonts</key>
    <array>
      <string>MaterialCommunityIcons.ttf</string>
    </array>
    
    1. 进入iOS目录执行pod install,之后重新编译iOS项目
  • Android手动补全配置(自动链接失效时)

    1. 打开android/app/build.gradle,在android代码块内添加一行:
    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
    
    1. 进入Android目录执行./gradlew clean清理缓存,再重新编译项目
  • 如果用的是Expo框架
    得先在app.json里声明字体:

    {
      "expo": {
        "fonts": [
          {
            "asset": "node_modules/react-native-vector-icons/Fonts/MaterialCommunityIcons.ttf"
          }
        ]
      }
    }
    

    然后安装expo-font依赖:expo install expo-font,还要在App启动时提前加载字体:

    import { useFonts } from 'expo-font';
    import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
    
    export default function App() {
      const [fontsLoaded] = useFonts({
        'MaterialCommunityIcons': require('@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts/MaterialCommunityIcons.ttf'),
      });
    
      if (!fontsLoaded) {
        return null; // 也可以写个加载中的组件
      }
    
      return (
        // 你的导航组件代码
      );
    }
    

最后确认下react-native-vector-icons版本和你的React Native版本兼容,一般最新版本适配主流RN版本,要是版本差太多可以考虑升级或降级匹配。

内容的提问来源于stack exchange,提问作者Mani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 00:20:29