Reputation: 3582
I'm want to use sans-serif-condensed in jetpack compose, but for the life of me, I can't find it anywhere within compose itself?
Am I just blind, or will I need to do something like import the font and set it all manually?
Upvotes: 0
Views: 295
Reputation: 14837
You can use the fontFamily
attribute to specify the font family.
Text("Hello World", fontFamily = FontFamily.Serif)
By default, Jetpack compose has only 5 Font Families,
Default
, SansSerif
, Serif
, Monospace
and Cursive
.
If you need any other font family (which seems to be your case), you have to add it as mentioned here.
Steps
Download or Get the required fonts files and add them to the res/fonts
directory.
Create FontFamily
like this,
val firaSansFamily = FontFamily(
Font(R.font.firasans_light, FontWeight.Light),
Font(R.font.firasans_regular, FontWeight.Normal),
Font(R.font.firasans_italic, FontWeight.Normal, FontStyle.Italic),
Font(R.font.firasans_medium, FontWeight.Medium),
Font(R.font.firasans_bold, FontWeight.Bold)
)
Use like this,
Text(..., fontFamily = firaSansFamily, fontWeight = FontWeight.Light)
Text(..., fontFamily = firaSansFamily, fontWeight = FontWeight.Normal)
Upvotes: 1