Skip to content

Instantly share code, notes, and snippets.

@SurajBahadur
Created March 22, 2022 07:21
Show Gist options
  • Save SurajBahadur/dbf896d9613661e1144e7c64111a5edc to your computer and use it in GitHub Desktop.
Save SurajBahadur/dbf896d9613661e1144e7c64111a5edc to your computer and use it in GitHub Desktop.
Font Awesome web font in android.
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) {
}
}
}
@SurajBahadur
Copy link
Author

SurajBahadur commented Mar 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment