react-native - console.error : "fontFamily "Material Icons" 不是系统字体,还没有通过 Font.loadAsync 加载
问题描述
我正在尝试从 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 时,最好使用内置的图标。
世博其实是自带的react-native-vector-icons
。所以你不需要安装任何东西。您可以从@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"
/>
检查图标是否存在也是值得的,您可以在目录中执行此操作。
推荐阅读
- django - 使用 Pycharm 而不是 Visual Studio 继续项目
- python - Sphinx 本身是否支持有关副作用的文档?
- azure - 如何从 Azure API 管理检测用户注册事件?
- keras - Keras“class_weights”参数可用于回归?
- r - 如何从数据集中获取百分位数?
- python - 自动将破折号添加到 tkinter 中的输入框
- amp-html - Google Pages Speed Tool 不支持 AMP 页面?
- python - 如何将滑块中的值存储为对象创建可以使用的整数
- css - MailChimp 中的中心按钮
- python - 无法从子目录导入 python 模块