How to change the font on the TextView?

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

    When your font is stored inside res/asset/fonts/Helvetica.ttf use the following:

    Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/Helvetica.ttf"); 
    txt.setTypeface(tf);
    

    Or, if your font file is stores inside res/font/helvetica.ttf use the following:

    Typeface tf = ResourcesCompat.getFont(this,R.font.helvetica);
    txt.setTypeface(tf);
    

提交回复
热议问题