React Native Android FontFamily无法更改或不起作用

时间:2018-11-05 13:01:01

标签: android react-native text fonts font-awesome

RNN 0.57,Android模拟器。

我正在尝试更改fontFamily,看来无论fontFamilyFont都不会改变。

<View>
   <Text style={{fontSize:24, fontFamily: 'Feather', color:'black'}}>Title Text Test</Text>
 </View>

结果始终是这种字体

enter image description here

我尝试了Roboto,Feather,FontAwesome等,但没有变化,仍然显示与屏幕截图相同的字体。

enter image description here

有什么想法吗?有没有默认字体覆盖我的样式?

1 个答案:

答案 0 :(得分:0)

所有这些字体都是图标字体,通过react-native-vector-icons链接。要使用它们,您应该使用their api

import Icon from 'react-native-vector-icons/Feather'

如果要使用自定义字体,则需要手动将字体与项目链接。首先找到一些字体,并将它们放在项目根目录中的某个位置;我通常把我放在./src/assets/fonts

在您的package.json中添加:

"rnpm": {
  "assets": [
    "./src/assets/fonts"
  ]
}

然后运行react-native link,您将能够使用这些自定义字体。