console.error : "fontFamily "Material Icons";不是系统字体,还没有通过 Font.loadAsync 加载 [英] console.error : "fontFamily "Material Icons" is not a system font and has not been loaded through Font.loadAsync

查看:48
本文介绍了console.error : "fontFamily "Material Icons";不是系统字体,还没有通过 Font.loadAsync 加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 react-native-vector-icons/MaterialIcons 添加一个图标:

I'm trying to add an icon from react-native-vector-icons/MaterialIcons:

import Icon from 'react-native-vector-icons/MaterialIcons';

<View style={styles.picture}>
  { <Icon
    name="add-circle"
    onPress={() => alert("Add Picture")}
    color="green"
  /> }
</View>

但我得到:

console.error : "fontFamily "Material Icons" 不是系统字体并且尚未通过 Font.loadAsync 加载

console.error : "fontFamily "Material Icons" is not a system font and has not been loaded through Font.loadAsync

我尝试使用 Font.loadAsync

I tried using Font.loadAsync

await Font.loadAsync({'MaterialIcons': require('@expo/vector-icons/fonts/MaterialIcons.ttf')})

有什么想法吗?

推荐答案

当您使用 Expo 时,您最好使用其中内置的图标.

As you are using Expo you would be better using the Icons that are built into it.

Expo 实际上带有 react-native-vector-icons.所以你不需要安装任何东西.您可以从 @expo/vector-icons

Expo in fact comes with react-native-vector-icons. So you don’t need to install anything. You can just import the icons from @expo/vector-icons

https://docs.expo.io/versions/latest/guides/图标/

import { MaterialIcons } from '@expo/vector-icons';

<MaterialIcons
  name="add-circle"
  onPress={() => alert("Add Picture")}
  color="green"
/>

还值得检查图标是否存在,您可以在目录.

It is also worth checking that the icon exists, you can do this in the directory.

这篇关于console.error : "fontFamily "Material Icons";不是系统字体,还没有通过 Font.loadAsync 加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆