How to add custom font in react native android

后端 未结 13 1268
别那么骄傲
别那么骄傲 2020-12-01 12:28

I am learning react-native, trying to create some demo apps just for learning. I want to set fontFamily to roboto thin of my toolbar title.

<
13条回答
  •  猫巷女王i
    2020-12-01 13:00

    Update:

    From the cli docs, "rnpm" is deprecated and support for it will be removed in next major version of the CLI.

    Instead, create a react-native.config.js in your project folder

    module.exports = {
      assets: ['./assets/fonts'],
    };
    

    Put your fonts in ./assets/fonts. Reference your fonts (e.g. McLaren-Regular.ttf) in the styles prop, {fontFamily: 'McLaren-Regular'}. If you're using styled components, then font-family: McLaren-Regular

    No linking or legacy build settings needed for either platforms. If that didn't work (sometimes it doesn't for me), run npx react-native link, even if you're using autolinking.

提交回复
热议问题