When using Material theme builder, kotlin theme files are generated using downloadable Google fonts.
I wanted to change these fonts which are dynamically downloaded by the running application with fonts that were bundled with my Android Studio Kotlin Compose application. Here are the steps to do replace the downloadable fonts
- Download the kotlin theme and integrate it in your application's theme folder
- Download the font
- You can download the google font ttf files here.
- Alternatively work with any other ttf file you want to replace the downloadable Google fonts with
- Add the font to your project. (Elaborate instructions on adding fonts to your compose project here)
- In your project create a font folder under res (if it does not exist yet)
- Put the downloaded ttf files in this folder.
- Replace all dash characters "-" in the filename with underscores "_". Replace all uppercase characters in the filename with lowercace (optionally preceded by an underscore).
- Adapt ...ui.theme.Type.kt in your project
- Replace all occurences ofwith
Font(
googleFont = GoogleFont("theFontName"),
fontProvider = provider,
)Font(
R.font.the_font_filename
) - remove the provider variable and its initialisation
Test and run!
Additional cookbooks on adding fonts to your compose project: