How to change the font on the TextView?

前端 未结 16 724
清歌不尽
清歌不尽 2020-11-22 08:09

How to change the font in a TextView, as default it\'s shown up as Arial? How to change it to Helvetica?

16条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 08:42

    Best practice is to use Android Support Library version 26.0.0 or above.

    STEP 1: add font file

    1. In res folder create new font resource dictionary
    2. Add font file (.ttf, .orf)

    For example, when font file will be helvetica_neue.ttf that will generates R.font.helvetica_neue

    STEP 2: create font family

    1. In font folder add new resource file
    2. Enclose each font file, style, and weight attribute in the element.

    For example:

    
    
        
    
    

    STEP 3: use it

    In xml layouts:

    
    

    Or add fonts to style:

    
    

    For more examples you can follow documentation:

    Working with fonts

提交回复
热议问题