在RN开发过程中使用react-native-vector-icons,按照流程,怎么都加载不出来,始终显示为下图
解决:
在执行完一系列操作后,重新运行react-native run-android命令。
完整步骤:
- 根目录下使用:
npm install --save react-native-vector-icons // 下载库 react-native link react-native-vector-icons // 自动关联
npm install react-native-vector-icons --save
或yarn add react-native-vector-icons
安装。 - 成功后显示:
- Android端的配置(先更新安卓端)
// 进入android/app/build.gradle文件,添加如下内容: project.ext.vectoricons = [ iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ] ] apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
-
在项目中使用:
import Icon from 'react-native-vector-icons/FontAwesome'; .... <Icon name={'angle-right'} size={24} color={'#999'} />
-
最后执行 react-native run-android,RR刷新后成功显示: