Java 如何在android中检索可用/已安装字体的列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3532397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:36:20  来源:igfitidea点击:

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

javaandroidfonts

提问by ab11

In Java I would do something like:

在 Java 中,我会做类似的事情:

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

is there an Android equivalent?

有Android等价物吗?

采纳答案by matto1990

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

摘自 Mark Murphy 在 Android Developers 邮件列表上的回答:

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.

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

只有三种字体:normal (Droid Sans)、serif (Droid Serif) 和 monospace (Droid Sans Mono)。

虽然 WebKit 中的某个地方可能隐藏着其他字体,但 WebKit 之外的开发人员似乎无法访问它们。:-(

唯一的其他字体是您与应用程序捆绑在一起的任何 TrueType 字体。

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

编辑:Roboto 是 Android 4.0 中的一种新字体。您可以使用这个库项目在所有版本中使用它回到 API 级别 4 https://github.com/mcalliph/roboto-text-view

回答by Colin Pickard

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

android 中只有 3 种字体可用;正常 (Droid Sans)、衬线 (Droid Serif) 和等宽字体 (Droid Sans Mono)。

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

应用程序可以包含自己的 truetype 字体,但不能安装它们以供其他应用程序使用。

couple of links about the fonts:

关于字体的几个链接:

回答by maxx

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.

Android 包括 3 种基本字体,但与 iOS 不同的是,它允许您使用几乎任何您喜欢的字体。您可以简单地将它嵌入到您的应用程序中,而不是像 Apple 那样受限于预设的字体列表(Apple 不允许字体嵌入)。挺方便的。

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.

请注意,这是针对 Android 本身,但网络浏览器(包括基本预装的 Android 网络浏览器)确实支持所有标准 HTML 字体。

回答by Apostolos

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.

数组 ff[] 将包含所有字体文件。