1

Can anyone help me to define a custom class for android Textview with a custom font in kotlin?

Android
  • 1,420
  • 4
  • 13
  • 23
P A Gosai
  • 553
  • 5
  • 22

2 Answers2

4

create a folder "font" inside "res" folder and copy your font

enter image description here

   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:fontFamily="@font/muli_font"
      />

programmatically

 view.setTypeface(ResourcesCompat.getFont(context, R.font.muli_font))

you can download ".ttf" font from here

Praveen
  • 946
  • 6
  • 14
1
Follow following steps to set custom font:-

// Set your font as you want
val typeface = Typeface.createFromAsset(assets, "baamini.ttf")

// Set Your test
txtMessage.text = "Hello world" 

// Set the typeface
txtMessage.typeface = typeface 
Ram Kadam
  • 139
  • 7