簡體   English   中英

console.error : "fontFamily "Material Icons" 不是系統字體,還沒有通過 Font.loadAsync 加載

[英]console.error : "fontFamily "Material Icons" is not a system font and has not been loaded through 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 時,您最好使用其中內置的圖標。

Expo 實際上帶有react-native-vector-icons 所以你不需要安裝任何東西。 您可以從@expo/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"
/>

還值得檢查圖標是否存在,您可以在目錄中執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM