How to change fontFamily of TextView in Android

后端 未结 30 2418
感动是毒
感动是毒 2020-11-22 01:05

So I\'d like to change the android:fontFamily in Android but I don\'t see any pre-defined fonts in Android. How do I select one of the pre-defined ones? I don\'

30条回答
  •  你的背包
    2020-11-22 01:36

    One simple way is by adding the desired font in the project.

    Go to File->New->New Resource Directory Select font

    This will create a new directory, font, in your resources.

    Download your font (.ttf). I use https://fonts.google.com for the same

    Add that to your fonts folder then use them in the XML or programmatically.

    XML -

    
    

    Programatically -

     Typeface typeface = ResourcesCompat.getFont(this, R.font.your_font);
     textView.setTypeface(typeface); 
    

提交回复
热议问题