How to add custom font in react native android

后端 未结 13 1246
别那么骄傲
别那么骄傲 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条回答
  •  一向
    一向 (楼主)
    2020-12-01 12:55

    The best way to do it would be to create your own custom component for Text and import it from another file.

    Assuming you want to change the default font to "opensans-semibold" (that is the name I gave it after downloading it and saving it).

    TYPESCRIPT:

    import React from 'react';
    import { Text as DefaultText, StyleSheet } from 'react-native';
    
    export function Text(props : any) {
        return(
             {props.children} 
        )
    }
        
    const styles = StyleSheet.create({
        defaultStyles: {
            fontFamily: "opensans-semibold"
        }
    });
    

    Now import this anywhere else as:

    import { Text } from './path/to/component'

    and use it as you normally would.

提交回复
热议问题