Custom TypeFace in Kotlin Programmatically

Viewed 11466

How to set typeface of any TextView. Using java we do something like this

TextView tv = (TextView) findViewById(R.id.custom);
tv.setTypeface(null, Typeface.BOLD);

How such operation could be performed while using kotlin. Which will be the efficient way to do this in kotlin? Is there any better way provided with kotlin?

holder.itemView.title.typeface = ?
6 Answers

Kotlin Answer

If you want to use your custom typeface, Typeface.createFromAsset() helps for the job!

This example to use in Fragment. In Activity, you do not need to write "activity!!".

yourTextview.typeface = Typeface.createFromAsset(activity!!.assets, "fonts/Forza-Bold.otf")

If you want use default typefaces:

yourTextview.typeface = Typeface.DEFAULT_BOLD
Related