How to Retrieve a List of Available/Installed Fonts in Android

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

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

How i can get Android System fonts list that is already installed and apply to custom keyboard

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

From above original question i got my answer but i am extending my answer with what i really wanted to do. how can we access those font in our application.

We can access system from path using this function (Typeface.createFromFile("your file")

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

for(int i = 0 ; i < ff.length ; i++){
fontName.setText(file.getName());
fontName.setTypeface(Typeface.createFromFile(ff[i]));
}

How to get all font directory font names in andorid?

If you want to get all fonts inside main->res->font directory

Try something like this:

Kotlin

val fontFields = R.font::class.java.fields
val fonts = arrayListOf<Int>()

for (field in fontFields) {
try {
Log.i("TAG", field.name)
fonts.add(field.getInt(null))
} catch (e: Exception) {
e.printStackTrace()
}
}

for(font in fonts){
val typeface = appContext.resources.getFont(font)
println(typeface.isBold)
}

Java

Field[] fontFields = R.font.class.getFields();
ArrayList<Integer> fonts = new ArrayList<>();

for (Field field : fontFields) {
try {
Log.i("TAG", field.getName());
fonts.add(field.getInt(null));
} catch (Exception e) {
e.printStackTrace();
}
}

for (int font : fonts){
Typeface typeFace = appContext.getResources().getFont(font);
Log.i("TAG", String.valueOf(typeFace.isBold()));
}

What fonts are installed by default on Android?

There are only three system wide fonts in Android;

1 normal (Droid Sans),

2 serif (Droid Serif),

3 monospace (Droid Sans Mono).

Applications can install fonts for themselves, but not for system-wide use.

For more you can see List of fonts included with each device link

and

Since the Ice Cream Sandwich release, Roboto has been the standard typeface on Android.

Since Froyo, Noto has been the standard typeface on Android for all languages not covered by Roboto. Noto is also the standard typeface for all languages on Chrome OS.

Refer here

Obtain installed fonts as a list

You want the InstalledFontCollection class:

using System.Drawing.Text;
using (InstalledFontCollection fontsCollection = new InstalledFontCollection())
{
FontFamily[] fontFamilies = fontsCollection.Families;
List<string> fonts = new List<string>();
foreach (FontFamily font in fontFamilies)
{
fonts.Add(font.Source);
}
}

list every font a user's browser can display

The JavaScript version is a bit flaky. It gets fonts by iterating through known fonts and testing.

The most accurate way (albeit having to use a propriety plugin) is to use Flash. Here you can get the list of fonts without having to test for them individually using dimensions.

You are going have to decide whether to have an exact list at the expense of not working on some devices ( iDevices, browsers without Flash plugin, etc), or a partial list with better support via JavaScript only.

android itext using assets fonts in Android Studio

This is obvious: Android does not have Arial font.
You have to ship the appropriate font for your script (Persian) along with your application and read the font from resources/assets/etc.

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

UPD:

Once you have your file in assets, grab an AssetManager via getAssets() and use it to read the bytes from the font. This answer might be useful.

Afterwards you are free to create your font like this:

BaseFont.createFont("arial.ttf", BaseFont.IDENTITY_H, true, false, bytes, null);

Meanwhile, I strongly encourage you to read thoroughly on the licensing of the fonts that are shipped with Windows to determine whether you are able to copy-paste Arial font into your application and then use it like this (I doubt so).



Related Topics



Leave a reply



Submit