How to change the font on the TextView?

前端 未结 16 1064
清歌不尽
清歌不尽 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:34

    I finally got a very easy solution to this.

    1. use these Support libraries in app level gradle,

      compile 'com.android.support:appcompat-v7:26.0.2'
      compile 'com.android.support:support-v4:26.0.2'
      
    2. then create a directory named "font" inside the res folder

    3. put fonts(ttf) files in that font directory, keep in mind the naming conventions [e.g.name should not contain any special character, any uppercase character and any space or tab]
    4. After that, reference that font from xml like this

              

    In this example, times_new_roman_test is a font ttf file from that font directory

提交回复
热议问题