Search code examples
androidkotlintextviewcustom-exceptions

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


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


Solution

  • 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