What is the equivalent of “android:fontFamily=”sans-serif-light" in Java code?

后端 未结 6 1766
半阙折子戏
半阙折子戏 2020-12-23 15:46

My question is quite simple:

In every of my textview, I am currently using the attribute

android:fontFamily=\"sans-serif-light\"

6条回答
  •  囚心锁ツ
    2020-12-23 16:14

    Android 4.1 (API Level 16) and Support Library 26 and higher

    If you are using res -> font folder, you can use like this

      val typeface = ResourcesCompat.getFont(Context, R.font.YOUR_FONT)
      TextView.setTypeface(typeface)
    

提交回复
热议问题