Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

New to Android development. Why is my custom typeface font not showing up in the Type folder?

I’m pretty new to Android development (especially Jetpack Compose), so I’m sure I’m forgetting something stupidly easy!

I downloaded the custom Montserrat regular and bold fonts from Google (as .ttf files), created a font directory in my resources folder, renamed the fonts to follow naming conventions, dragged the fonts into the font directory, then tried to initialize them in the Type.kt file as a variable named Montserrat. I get an unresolved reference error and the Lint suggestion creates an XML file in the font directory. I have used custom fonts from Google many times before and followed the exact steps, but something is clearly not working!

I’d love to post screenshots, but I do not have enough reputation, unfortunately.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help is extremely appreciated!

Followed basic instructions to use custom fonts, and it is not initializing in the Type.kt folder.

>Solution :

If you’re using Jetpack Compose to build your Android app, you can specify custom fonts in your app’s typography object. You can then use the font property in the Text composable to apply the font to your text. Here’s an example

@Composable
fun MyApp() {
  val customFont = font(R.font.montserrat)
  Typography(
    h1 = TextStyle(
      font = customFont,
      fontSize = 24.sp
    )
  )
  // ...
}

You can then use this style in your app like this

@Composable
fun MyScreen() {
  Text("My headline", style = Typography.h1)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading