Created
March 6, 2018 16:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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