How can we create custom class of TextView with custom font in kotlin?

1k Views Asked by At

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

2

There are 2 best solutions below

0
Praveen On BEST ANSWER

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

0
Ram Kadam On
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