Tuesday, 22 March 2022

Font awesome web font in android

  No comments
You have to download fontawesome-webfont.ttf from this link and add it to the asset folder.

class TextViewFontAwsome : androidx.appcompat.widget.AppCompatTextView {
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context!!, attrs, defStyle) {
init()
}
constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) {
init()
}
constructor(context: Context?) : super(context!!) {
init()
}
fun init() {
try {
val tf = Typeface.createFromAsset(context.assets, "fontawesome-webfont.ttf")
typeface = tf
} catch (exp: Exception) {
}
}
}

Image


No comments :

Post a Comment