ab11
ab11

Reputation: 20090

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

In Java I would do something like:

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

is there an Android equivalent?

Upvotes: 42

Views: 81289

Answers (6)

Michael S
Michael S

Reputation: 1865

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

Upvotes: 2

calamari
calamari

Reputation: 337

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").

Upvotes: 0

Apostolos
Apostolos

Reputation: 3445

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.

Upvotes: 29

matt-oakes
matt-oakes

Reputation: 3856

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

Upvotes: 42

maxx
maxx

Reputation: 53

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.

Upvotes: -3

Colin Pickard
Colin Pickard

Reputation: 46653

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:

Upvotes: 8

Related Questions