在Android上设置默认字体 [英] Default font set on Android

查看:196
本文介绍了在Android上设置默认字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我大多数Android设备上的捆绑字体是什么,特别是对于网页?



就像: DroidSans.ttf - > Roboto-Regular.ttf DroidSans-Bold.ttf - > Roboto-Bold.ttf



编辑:我引用家族名称( http://jsfiddle.net/9z3tD/9/ 呈现相同)。 CSS区分类似于 serif 和引用serif的泛型关键字,其引用的名称恰好是serif ;但xml配置没有区别,所以我在android中猜测或者语法是指名称为serif的字体。但如果您创建自定义WebView并将其配置为将通用关键字映射到其他字体(可能会 /WebSettings.html#setSerifFontFamily(java.lang.String)rel =nofollow noreferrer> setSerifFontFamily() 和朋友)。



然后是 fallback_fonts .xml 。这些没有名字;例如你不能说 font-family:Droid Sans Fallback

但是他们都被试图为其他的每一个缺失的字形字体。大概还可以选择 font-variant of elegant 和设置文本 lang =ja

但是我没有看到Droid Sans Fallback所有这样的回退在WebKit中不起作用: - (






免责声明:以上适用于股票Android,



在理论上,制造商可能会在未经测试的情况下,使用其他字体,例如我听说三星做的事实。在实践中所有Android设备上的屏幕截图BrowserStack已经所有 - 包括三星 - 看着我未经训练的眼睛是Roboto或Droid,差异只是android版本...
不过这里是银河S3被捕捉不到锯齿格鲁吉亚 serif ,因此 不同。



Firefox 是浏览器做得不同的一个很好的例子 - 他们切换到打开Sans和Charis SIL Compact ,然后用清除Sans替换了Open Sans。

完整配置位于
libpref / init / all.js ,依赖。

据我所知,Firefox忽略system_fonts.xml的别名,例如 Georgia 会导致无字体。

OTOH,旧版本(测试30,34)允许您按名称引用系统字体,甚至到Droid Sans Fallback ,但此无法在FF 36,37 (这两个结果是 http://codepen.io/cben/pen/VYgPEE ,使用AdobeBlank意味着当您看到chars时,






另请参阅相关答案关于应用程序可用的字体。


Can anyone tell me what are the bundled fonts on most Android devices, specifically for web pages?

Just like Windows has their bundled fonts or Mac font lists, what are the fonts that come with most Android phones and tablets? Can anyone point to a list on the web?

I'm making web pages and want to set up my CSS to degrade gracefully from using newer fonts to just plain ol' "sans-serif" and "serif" font families. Thx.

解决方案

Expanding upon Grstmo's answer:

system_fonts.xml defines mapping from font-family to actual font files. So let's try these:

<div style="font-family: sans-serif; font-style: normal">Regular</div>
<div style="font-family: sans-serif; font-style: italic">Italic</div>
<div style="font-family: sans-serif; font-weight: bold">Bold</div>
<div style="font-family: sans-serif; font-weight: bold; font-style: italic">Bold-italic</div>

<div style="font-family: sans-serif-light; font-style: normal">Light</div>
<div style="font-family: sans-serif-light; font-style: italic">Light-italic</div>

<div style="font-family: sans-serif-thin; font-style: normal">Thin</div>
<div style="font-family: sans-serif-thin; font-style: italic">Thin-italic</div>

<div style="font-family: sans-serif-condensed; font-style: normal">Condensed regular</div>
<div style="font-family: sans-serif-condensed; font-style: italic">Condensed italic</div>
<div style="font-family: sans-serif-condensed; font-weight: bold">Condensed bold</div>
<div style="font-family: sans-serif-condensed; font-weight: bold; font-style: italic">Condensed bold-italic</div>

<div style="font-family: serif; font-style: normal">Serif Regular</div>
<div style="font-family: serif; font-style: italic">Serif Italic</div>
<div style="font-family: serif; font-weight: bold">Serif Bold</div>
<div style="font-family: serif; font-weight: bold; font-style: italic">Serif Bold-italic</div>

<!-- "Droid Sans" actually gives you Roboto. -->
<div style="font-family: &quot;Droid Sans&quot;; font-style: normal">Droid Sans Regular</div>
<div style="font-family: &quot;Droid Sans&quot;; font-weight: bold">Droid Sans Bold</div>

<div style="font-family: monospace; font-style: normal">Monospace Regular</div>

http://jsfiddle.net/9z3tD/4/ => (tested on android 4.2)

EDIT: "Droid Sans" in the screenshot is clearly Roboto. The config supports it but turns out the underlying file is a simlink: DroidSans.ttf -> Roboto-Regular.ttf, DroidSans-Bold.ttf -> Roboto-Bold.ttf

EDIT: It doesn't seem to matter whether I quote the family names (http://jsfiddle.net/9z3tD/9/ renders the same). CSS distinguishes between generic keywords like serif and quoted "serif" which refers to a font whose name happens to be "serif"; but the xml config makes no distinction so I guess in android either syntax refers to a font whose name is "serif". But there may be a difference if you create a custom WebView and configure it to map generic keywords to other fonts (setSerifFontFamily() and friends).

Then there are fallback_fonts.xml. These have no names; e.g. you CAN'T say font-family: "Droid Sans Fallback".
But all of them are suppossed to be tried for every missing glyph in other fonts. Presumably one can even choose a subset using font-variant of "elegant" or "compact" and by setting text lang="ja"?
However I don't see Droid Sans Fallback being used at all so perhaps fallbacks don't work in WebKit :-(


Disclaimer: The above applies to stock Android, using stock browser and/or Chrome. I believe it also applies to WebView (with default config) but haven't tested.

In theory manufacturers may use other fonts, e.g. I heard rumors Samsung does it. In practice screenshots on all android devices BrowserStack had all — including Samsungs — look to my untrained eyes to be Roboto or Droid, the differences being just android releases... However here is Galaxy S3 caught not aliasing Georgia to serif so something differs.

Firefox is a good example of a browser doing it differently — they switched to Open Sans and Charis SIL Compact, then replaced Open Sans with Clear Sans.
The full config is in libpref/init/all.js and is language-dependent.
As far as I can tell, Firefox disregards the system_fonts.xml's aliases, e.g. Georgia results in a sans font.
OTOH, older versions (tested 30, 34) allowed you to refer to system fonts by name, even to Droid Sans Fallback but this doesn't work on FF 36, 37 (these 2 results are for http://codepen.io/cben/pen/VYgPEE, use of AdobeBlank means that when you see chars, that font was used).


See also relevant answer about fonts available to apps.

这篇关于在Android上设置默认字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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