Created
April 18, 2022 05:17
-
-
Save raipankaj/bcdc3b4e37bed373a5fe6c7a47f80281 to your computer and use it in GitHub Desktop.
Download font support in Jetpack Compose
This file contains hidden or 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
| @OptIn(ExperimentalTextApi::class) | |
| private fun getGoogleFontFamily( | |
| name: String, | |
| provider: GoogleFont.Provider = googleFontProvider, | |
| weights: List<FontWeight> | |
| ): FontFamily { | |
| return FontFamily( | |
| weights.map { | |
| Font(GoogleFont(name), provider, it) | |
| } | |
| ) | |
| } | |
| @OptIn(ExperimentalTextApi::class) | |
| private val googleFontProvider: GoogleFont.Provider by lazy { | |
| GoogleFont.Provider( | |
| providerAuthority = "com.google.android.gms.fonts", | |
| providerPackage = "com.google.android.gms", | |
| certificates = R.array.com_google_android_gms_fonts_certs | |
| ) | |
| } | |
| @OptIn(ExperimentalTextApi::class) | |
| val AppFontTypography = Typography( | |
| defaultFontFamily = getGoogleFontFamily( | |
| name = "Poppins", | |
| weights = listOf( | |
| FontWeight.Normal, | |
| FontWeight.Bold, | |
| FontWeight.ExtraLight, | |
| FontWeight.SemiBold | |
| ) | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment