16

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. enter image description here

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

AADProgramming
  • 6,077
  • 11
  • 38
  • 58
  • 5
    "Only Android Studio 2.4 includes support for all the new developer features available with Android O." - https://developer.android.com/preview/migration.html#bfa – Mike M. Apr 01 '17 at 04:48
  • @MikeM. ok, thanks! I am updating Android studio to 2.4 now from Canary channel. Will update my answer if I could see the font resource type in AS-2.4 – AADProgramming Apr 01 '17 at 04:51
  • Anyone got any workaround now? Without updating AS out of stable version – Pulkit Sep 04 '17 at 06:08
  • I am not able to preview the ttf file in fonts folder in android studio – Amit Verma Oct 09 '17 at 10:40

5 Answers5

33

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.

Community
  • 1
  • 1
Jacobski
  • 741
  • 6
  • 10
7

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.

enter image description here

AADProgramming
  • 6,077
  • 11
  • 38
  • 58
  • Do you know why it is not visible in Android Studio 3.0 Beta 4 – Pulkit Sep 05 '17 at 09:25
  • Do I need to set a specific `minSdkVersion`? I have Android Studio 3.0 and still can not see `font` type. `compileSdkVersion 26 buildToolsVersion '26.0.2' defaultConfig { applicationId "com.foo.bar" minSdkVersion 19 targetSdkVersion 26` – AlexAndro Oct 30 '17 at 10:13
2

You need to update Android studio to 3.0 beta 2 to use all latest features of font family

Mohit Goel
  • 722
  • 1
  • 8
  • 18
1

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.

sednanre
  • 478
  • 5
  • 16
-1

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
Kiran Koravi
  • 164
  • 2
  • 11
  • 3
    This is not what the OP is asking about. They're trying to use the new font _resources_ available in Android O. – Mike M. Apr 01 '17 at 06:13
  • 1
    As @MikeM. i am not looking for how to use custom font. i am trying out the new Android O way of adding a font – AADProgramming Apr 01 '17 at 08:10