Skip to content

Instantly share code, notes, and snippets.

@ditn
Created March 6, 2018 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ditn/9e2d8111f0d5dc47ae7f93fd43d2499d to your computer and use it in GitHub Desktop.
Save ditn/9e2d8111f0d5dc47ae7f93fd43d2499d to your computer and use it in GitHub Desktop.
An example of an Extension Function that applies a loaded font to a TextView
/**
* Loads a font via the Support Library downloadable font system and applies it to a TextView. If this
* function fails, it will do so silently.
*
* @param customFont A [CustomFont] object that encapsulates the query to be sent to the fonts provider
*/
fun TextView.setCustomFont(customFont: CustomFont) {
loadFont(context, customFont) {
this.typeface = it
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment