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

允我心安 提交于 2021-01-28 01:35:57

问题


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>

but i'm getting:

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

I tried using Font.loadAsync

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

Any ideas?


回答1:


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

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/icons/

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.



来源:https://stackoverflow.com/questions/55030847/console-error-fontfamily-material-icons-is-not-a-system-font-and-has-not-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!