Can anyone help me to define a custom class for android Textview
with a custom font in kotlin
?
Asked
Active
Viewed 1,067 times
1
-
you don't need a custom class to use custom font. Normal TextView already supports it. – Vladyslav Matviienko Jun 04 '19 at 04:52
-
If want to add for only Custom Font then it supports already and you don't need to make a new custom class. – Rahul Kushwaha Jun 04 '19 at 04:53
-
@VladyslavMatviienko can you please give me an example? – P A Gosai Jun 04 '19 at 04:54
-
Inspite of this ,If want to make a custom class this link may help you:https://stackoverflow.com/questions/9477336/how-to-make-a-custom-textview – Rahul Kushwaha Jun 04 '19 at 04:54
-
1just search for `textview android kotlin font`, should take you around 12 seconds to find answer – Vladyslav Matviienko Jun 04 '19 at 04:55
2 Answers
4
create a folder "font" inside "res" folder and copy your font
<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