How to retrieve a list of available/installed fonts in android?
Asked Answered
A

6

41

In Java I would do something like:

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

is there an Android equivalent?

Alkali answered 20/8, 2010 at 15:32 Comment(0)
U
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

Understand answered 20/8, 2010 at 15:41 Comment(7)
I... can actually work with that... Gotta appreciate the simplicity of options.Mclyman
Can anyone say font fragmentation? /jkGuardant
There's no problem. You can use any font you like and just include it in your project. Works perfectlyUnderstand
until you work in web development, and start cursing at Android for not even supporting Arial. That's just sad.Soapy
Is it still true there is only Droid? What is this Roboto thing? developer.android.com/design/style/typography.htmlLei
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 github.com/mcalliph/roboto-text-viewUnderstand
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.Hebrides
A
29

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.

Annia answered 11/3, 2016 at 7:47 Comment(6)
how can i used particular font file and apply that font in rich text ?Blatherskite
This is the actual answer to OP's question.Lilienthal
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.Daman
I am sorry @Blatherskite 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.Annia
@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 ...)Annia
@Annia Thanks for the reply.Daman
S
8

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:

Supreme answered 20/8, 2010 at 15:40 Comment(1)
From android 4.1 - JellyBean, the following Roboto font families are available: https://mcmap.net/q/53676/-how-to-change-fontfamily-of-textview-in-androidExogamy
I
2

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()

Istic answered 22/1, 2022 at 23:58 Comment(1)
With this, I see 288 whereas with Apostolos' answer there are 328 filesIstic
G
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").

Genesia answered 26/1, 2021 at 3:19 Comment(0)
A
-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.

Ashtray answered 2/11, 2011 at 8:50 Comment(3)
This is no longer true - iOS 4+ allows apps to embed their own fonts, in addition to the 58 font families provided by iOS.Waverley
And those 58 cover the gamut if you're not doing anything off-the-wall with fonts: iosfonts.comBrianabriand
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.Coumas

© 2022 - 2024 — McMap. All rights reserved.