39

In Java I would do something like:

java.awt.GraphicsEnvironment ge = 
                      java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = ge.getAllFonts(); 

is there an Android equivalent?

assylias
  • 321,522
  • 82
  • 660
  • 783
ab11
  • 19,770
  • 42
  • 120
  • 207

6 Answers6

42

Taken from Mark Murphy's answer on the Android Developers mailing list:

http://developer.android.com/reference/android/graphics/Typeface.html

There are only three fonts: normal (Droid Sans), serif (Droid Serif), and monospace (Droid Sans Mono).

While there may be additional fonts buried in WebKit somewhere, they appear to be inaccessible to developers outside of WebKit. :-(

The only other fonts are any TrueType ones you bundle with your application.

Edit: Roboto is a new font which came in with Android 4.0. You can use this library project to use it in all versions back to API level 4 https://github.com/mcalliph/roboto-text-view

matto1990
  • 3,766
  • 2
  • 27
  • 32
  • 5
    I... can actually work with that... Gotta appreciate the simplicity of options. – hndcrftd Sep 01 '11 at 14:59
  • 1
    Can anyone say font fragmentation? /jk – Marius Oct 24 '11 at 16:34
  • There's no problem. You can use any font you like and just include it in your project. Works perfectly – matto1990 Nov 03 '11 at 10:34
  • 4
    until you work in web development, and start cursing at Android for not even supporting Arial. That's just sad. – Antony Jan 27 '12 at 21:02
  • Is it still true there is only Droid? What is this Roboto thing? http://developer.android.com/design/style/typography.html – i_am_jorf Jan 28 '13 at 17:18
  • Roboto is a new font which came in with Android 4.0. You can use this library project to use it in all versions back to API level 4 https://github.com/mcalliph/roboto-text-view – matto1990 Apr 09 '13 at 13:49
  • I don't see how this is marked as the answer as it does not address to the issue of "listing the installed fonts". Apostolos' should be the accepted answer. – Renato Back Sep 25 '16 at 06:14
28

Regarding the actual question, here is a way to create a list of all available fonts installed:

String path = "/system/fonts";
File file = new File(path);
File ff[] = file.listFiles();

Array ff[] will contain all the font files.

Apostolos
  • 3,115
  • 25
  • 28
  • how can i used particular font file and apply that font in rich text ? – Vrajesh Nov 02 '17 at 19:38
  • This is the actual answer to OP's question. – user-44651 Mar 21 '18 at 13:58
  • How to identify if particular font only has numbers or only has alphabets? I want to use only fonts which is complete set of alphanumeric + special characters. – Myth Jul 31 '18 at 10:59
  • I am sorry @Vrajesh for not responding - I just got a notification on this thread by stackoverflow ...I am not sure what you are asking ... If you are asking something more than just picking up a font file from the ff[] list, it's beyond the question and at this moment I don't have an answer. – Apostolos Aug 01 '18 at 11:54
  • @Nougat, your question is also bequond this thread's question. However, I can suggest off hand that you try to print all characters with one or more of the fonts in the list and see what you get ... (There might be a shorter and more efficient method though ...) – Apostolos Aug 01 '18 at 11:58
  • @Apostolos Thanks for the reply. – Myth Aug 08 '18 at 12:05
9

There are only 3 fonts available as part of android; normal (Droid Sans), serif (Droid Serif), and monospace (Droid Sans Mono).

Apps can include their own truetype fonts but can't install them for use by other apps.

couple of links about the fonts:

Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
  • 1
    From android 4.1 - JellyBean, the following Roboto font families are available: http://stackoverflow.com/a/13329907/502187 –  Dec 16 '12 at 14:38
1

From Android 29, giving you an actual collection of android.graphics.fonts.Font, there is SystemFonts.getAvailableFonts()

https://developer.android.com/reference/kotlin/android/graphics/fonts/SystemFonts?hl=en#getAvailableFonts()

clwhisk
  • 1,805
  • 1
  • 18
  • 17
0

This answer isn't a programmatic solution, but the actual ttf fonts seem to be stored in the /system/fonts directory. Use adb shell ls /system/fonts to list them, or adb pull /system/fonts to transfer all of them to the connected computer (adb will create a folder named "fonts").

calamari
  • 329
  • 2
  • 8
-3

Android includes 3 base fonts, but unlike iOS, allow you to use just about any font you'd like. You can simply embed it with your app, instead of being limited to a preset list of fonts like Apple does (Apple doesn't allow font embedding). Pretty convenient.

Note that this is for Android itself, but web browsers (including the basic pre-installed Android web browser) does support all the standard HTML fonts.

maxx
  • 53
  • 21
    This is no longer true - iOS 4+ allows apps to embed their own fonts, in addition to the 58 font families provided by iOS. – wildcard Nov 12 '11 at 06:45
  • 8
    And those 58 cover the gamut if you're not doing anything off-the-wall with fonts: http://iosfonts.com –  Dec 20 '11 at 08:04
  • 6
    Not helpful to come along over a year after the OP and use your answer just as an opportunity to slam iOS -- and ineffectively at that. No information in this answer that is useful to the OP nor to those of us coming along later looking for an answer to the question. – Craig Oct 13 '12 at 14:24