Android中的默认字体系列是什么? [英] What is the default font family in Android?

查看:1662
本文介绍了Android中的默认字体系列是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从API 16开始,Jellybean Roboto作为可用字体家族被引入使用。看看Android 16 这里有什么新。



指定 android:fontFamily =sans-serif(API 16+中的Roboto) TextView TextView 的默认 fontFamily


$ b

 < TextView 
android:layout_width =wrap_content
android :layout_height =wrap_content/>

相当于

 < TextView 
android:layout_width =wrap_content
android:layout_height =wrap_content
android:fontFamily =sans-serif/>



From 材料设计排版网站


Roboto和Noto是Android和Chrome上的标准字体。


From Wiki
$ b


Roboto is a由Google开发的无衬线字体系列作为其移动操作系统Android的
系统字体。

我不请参阅文档,了解Android的默认 fontFamily 是什么。请参阅参考资料:


解决方案

d.android.com没有关于字体名称的文档。但是,如果您查看AOSP,默认字体将加载到 android.graphics。* 中。 FontListParser 将加载来自 /system/etc/fonts.xml (Android 5.0+)或 /system/etc/system_fonts.xml (Android 4.1)。默认的字体在 Typeface#init < a>。

这两个XML文件有一些文档。第一个字体是默认的字体。你可以从你的设备上取得/system/etc/fonts.xml。设备制造商或自定义ROM可能会更改默认系统字体。
$ b

fonts.xml (API 21 +)


注意:这是系统字体配置的较新(L)版本,
支持更加丰富的权重选择。有些应用程序会期望更旧的
版本,所以请尽可能使system_fonts.xml和fallback_fonts.xml保持同步
,即使框架只会读取此文件。



所有带有姓氏的字体都会被添加到默认列表中。字体根据匹配选择
:完整的BCP-47语言标签,包括脚本,然后是
语言,最后是订单(包含字形的第一个字体)。

出场顺序也是重量匹配的决胜者。这是
之所以900磅重的Roboto先于700个重量 - 我们b $ b更喜欢前者当800重量的要求。因为大胆的跨越
有效地增加了300的重量,这确保900是大胆的
搭配500的重量,确保足够的对比度。


system_fonts.xml (API 16-20)
$ b


系统字体 p>

该文件列出了所有支持的字形默认使用的字体系列。
每个条目由一个系列,该系列支持的各种名称以及
最多四个字体文件组成。字体文件按
支持的样式顺序排列:常规,粗体,斜体和粗体 - 斜体。如果列出的样式少于四种,那么
中没有关联字体文件的样式将被列出的其他字体文件支持。



第一族也是默认的字体,处理字体请求,没有指定
特定的字体名称。

系统字体不处理任何字形将导致搜索后备字体。
文件/system/etc/fallback_fonts.xml中指定了默认的回退字体,
是一个可选文件,供应商可能会提供该文件来指定其他回退字体以使用
/vendor/etc/fallback_fonts.xml。

如果解析fonts.xml文件,您可以找到哪个字体族使用哪种字体(请参阅此处):

 ╔════╦════════════════════════════╦════════════ ═════════
║║FONT FAMILY║TTF文件║
╠═══════════════════════════ ═══════════════ b $ b║1║随便║ComingSoo n.ttf║
║2║草书║DancingScript-Regular.ttf║
║3║等宽字体║DroidSansMono.ttf║
║4║sans-serif║Roboto-Regular.ttf║
║5║sans-serif-black║Roboto-Black.ttf║
║6║sans-serif-condensed║RobotoCondensed-Regular.ttf║
║7║sans-serif-condensed- light║RobotoCondensed-Light.ttf║
║8║sans-serif-light║Roboto-Light.ttf║
║9║sans-serif-medium║Roboto-Medium.ttf║
║10║sans-serif-smallcaps║CarroisGothicSC-Regular.ttf║
║11║sans-serif-thin║Roboto-Thin.ttf║
║12║serif║NotoSerif-Regular.ttf║
║13║serif-monospace║CutiveMono.ttf║
╚══════════ ══════════════════════════╩═══════════════════════ ═══════


Starting in API 16, Jellybean Roboto was introduced as available font family to use. See whats "new" in Android 16 here.

Specifying android:fontFamily="sans-serif"(Roboto in API 16+) on a TextView the default fontFamily of the TextView?

Is

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

equivalent to

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="sans-serif" />

?

From Material design typography website:

"Roboto and Noto are the standard typefaces on Android and Chrome."

From Wiki,

"Roboto is a sans-serif typeface family developed by Google as the system font for its mobile operating system Android."

I do not see in the docs what the default fontFamily of Android is. See references:

解决方案

There is no documentation on d.android.com for font family names. However, if you look at AOSP, the default fonts are loaded in android.graphics.*. The FontListParser loads the default fonts from /system/etc/fonts.xml (Android 5.0+) or /system/etc/system_fonts.xml (Android 4.1). The default fonts are loaded in Typeface#init.

The two XML files have some documentation. The first font is the default font. You can pull /system/etc/fonts.xml from your device. A device manufacturer or custom ROM may change the default system fonts.

fonts.xml (API 21+)

NOTE: this is the newer (L) version of the system font configuration, supporting richer weight selection. Some apps will expect the older version, so please keep system_fonts.xml and fallback_fonts.xml in sync with any changes, even though framework will only read this file.

All fonts withohut names are added to the default list. Fonts are chosen based on a match: full BCP-47 language tag including script, then just language, and finally order (the first font containing the glyph).

Order of appearance is also the tiebreaker for weight matching. This is the reason why the 900 weights of Roboto precede the 700 weights - we prefer the former when an 800 weight is requested. Since bold spans effectively add 300 to the weight, this ensures that 900 is the bold paired with the 500 weight, ensuring adequate contrast.

system_fonts.xml (API 16-20)

System Fonts

This file lists the font families that will be used by default for all supported glyphs. Each entry consists of a family, various names that are supported by that family, and up to four font files. The font files are listed in the order of the styles which they support: regular, bold, italic and bold-italic. If less than four styles are listed, then the styles with no associated font file will be supported by the other font files listed.

The first family is also the default font, which handles font request that have not specified specific font names.

Any glyph that is not handled by the system fonts will cause a search of the fallback fonts. The default fallback fonts are specified in the file /system/etc/fallback_fonts.xml, and there is an optional file which may be supplied by vendors to specify other fallback fonts to use in /vendor/etc/fallback_fonts.xml.

If you parse the fonts.xml file, you can find which font family uses which typeface (see here):

╔════╦════════════════════════════╦═════════════════════════════╗
║    ║ FONT FAMILY                ║ TTF FILE                    ║
╠════╬════════════════════════════╬═════════════════════════════╣
║  1 ║ casual                     ║ ComingSoon.ttf              ║
║  2 ║ cursive                    ║ DancingScript-Regular.ttf   ║
║  3 ║ monospace                  ║ DroidSansMono.ttf           ║
║  4 ║ sans-serif                 ║ Roboto-Regular.ttf          ║
║  5 ║ sans-serif-black           ║ Roboto-Black.ttf            ║
║  6 ║ sans-serif-condensed       ║ RobotoCondensed-Regular.ttf ║
║  7 ║ sans-serif-condensed-light ║ RobotoCondensed-Light.ttf   ║
║  8 ║ sans-serif-light           ║ Roboto-Light.ttf            ║
║  9 ║ sans-serif-medium          ║ Roboto-Medium.ttf           ║
║ 10 ║ sans-serif-smallcaps       ║ CarroisGothicSC-Regular.ttf ║
║ 11 ║ sans-serif-thin            ║ Roboto-Thin.ttf             ║
║ 12 ║ serif                      ║ NotoSerif-Regular.ttf       ║
║ 13 ║ serif-monospace            ║ CutiveMono.ttf              ║
╚════╩════════════════════════════╩═════════════════════════════╝

这篇关于Android中的默认字体系列是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆