在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刷新後成功顯示: