Reputation: 6345
I was going through the new Android O features, and one of the new thing is now app can add fonts directly into res
folder. As per the android documentation for working with fonts, one of the 1st step is to create a new resource type named "font" using Right-click the res folder and go to New > Android resource directory.
But I could not see "font" option available for resource type in the drop down in android studio.
I am not able to see "font" option in the drop down, and hence I am unable to create font android resource directory.
My Android studio details:
Android Studio 2.3 Build #AI-162.3764568, built on February 24, 2017 JRE: 1.8.0_112-release-b06 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Upvotes: 17
Views: 16593
Reputation: 771
One thing I noticed is that the drop down is actually scrollable but because the scrollbar is quite dark, others might not notice it. I can't find "font" at first until I scrolled it downwards.
Upvotes: 35
Reputation: 528
In case you're wondering how to use these new fonts programmatically (which took me some time to figure out), refer to this tutorial from SEGUN. He teaches the following:
Java:
Typeface typeface = ResourcesCompat.getFont(this, R.font.app_font);
fontText.setTypeface(typeface);
Kotlin:
val myCustomFont : Typeface? = ResourcesCompat.getFont(this, R.font.my_font)
fontText.typeface = myCustomFont
Note: you'll need to have the .ttf
font downloaded in your project to do so - not just the .xml
for the downloadable font.
Upvotes: 1
Reputation: 742
You need to update Android studio to 3.0 beta 2 to use all latest features of font family
Upvotes: 2
Reputation: 6345
As said by Mike in comments, currently Android Studio 2.4 includes support for all the new developer features available with Android O.
I used Android Studio 2.4 Preview from Canary Channel, & I could see the option for "font" when choosing the Android resource directory.
Below is the image for the same.
Upvotes: 7
Reputation: 164
Step 1: create new folder name it 'assets' under app/src/main manually.
Step 2: create 'fonts' name folder inside assets folder.
Step 3: put your .ttf files under fonts folder.
then check your studio project structure.
Upvotes: -1