【发布时间】:2019-03-06 19:30:16
【问题描述】:
我正在尝试从 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 加载
我尝试使用 Font.loadAsync
await Font.loadAsync({'MaterialIcons': require('@expo/vector-icons/fonts/MaterialIcons.ttf')})
有什么想法吗?
【问题讨论】:
-
这是一个 Expo 应用程序吗?
-
是的,这是我在 vs code 上运行的 expo 应用
-
react-native-vector-icons包含在 Expo 中。为什么要这样导入?您不需要这样做,您应该能够从@expo/vector-icons访问它们,而无需向您的package.json添加任何其他内容docs.expo.io/versions/latest/guides/icons -
确实有效,谢谢! :)
标签: react-native react-native-vector-icons vector-icons