问题
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.
Below is the image attached.
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
回答1:
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.
回答2:
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.
回答3:
You need to update Android studio to 3.0 beta 2 to use all latest features of font family
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/43152907/cannot-see-font-resource-type-in-android-studio