I’m trying to set a custom font to a TextView in my Android app using Kotlin. I’ve placed the font file (iran_sans.tff) in the assets folder and am using the following code:
binding.button.setOnClickListener {
val typeFace = Typeface.createFromAsset(assets, "iran_sans.tff")
binding.textView.typeface = typeFace
}
However, every time I click the button, the app crashes. I’ve verified that the font file is correctly placed in the assets folder.
Any suggestions or solutions would be greatly appreciated.
New contributor
Ali Habibi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.