簡體   English   中英

使用CSS font-family選擇不適用於Android的Droid字體

[英]Using CSS font-family to select Droid fonts not working on Android

我發現以下HTML代碼在Android上不起作用(它只使用默認字體:Droid Sans。在桌面上它正如預期的那樣工作。

<p style='font-family: "Droid Sans",sans-serif;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "Droid Sans Mono",monospace;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "Droid Serif",serif;'>vând whisky și tequila, preț fix.</p>

似乎Android只識別system_fonts.xml中定義的系列名稱( fonts.xml直到gingerbread)。 例如,為了獲得Droid Serif,你會被要求編寫通用的serif 有關詳情,請參閱此答案

哦,還有與“德羅伊德桑”一個怪癖:一個名字因為在4.0的配置,但.TTF是一個符號鏈接的Roboto。

<猜測>我可以看到Android的生命早期有人說“我們只會有三種字體,所以如果開發人員只使用通用名稱會更好,這樣我們總能替換它們”</ speculation>

但這很不幸。 您獲得的實際字體可能有所不同的原因有很多:

  • 在獲得Roboto家族之后,在4.0之前你會得到Droid家族。
  • Firefox正在捆綁Open Sans和Charis SIL並使用它們。
  • 制造商可能會用自己的字體替換3種字體。 編輯:我找不到任何實際發生的確認。

在所有這些情況下,如果我可以在我的字體堆棧中通過實際名稱引用特定字體,那將是很好的。 唉,我不能。

您的css中的其他字體可能沒有@ font-face聲明。 我想你只有一個Droid Sans。 每種字體都需要一個。 例如,在你的CSS中你應該有:

@font-face {
    font-family: 'DroidSans';
    src: url('font/DroidSans-webfont.eot?') format('eot'),
         url('font/DroidSans-webfont.woff') format('woff'),
         url('font/DroidSans-webfont.ttf') format('truetype'),
         url('font/DroidSans-webfont.svg#webfontw7zqO19G') format('svg');
    font-weight: normal;
    font-style: normal;

}

@font-face {
    font-family: 'DroidSansMono';
    src: url('font/DroidSans-Mono-webfont.eot?') format('eot'),
         url('font/DroidSans-Mono-webfont.woff') format('woff'),
         url('font/DroidSans-Mono-webfont.ttf') format('truetype'),
         url('font/DroidSans-Mono-webfont.svg#webfontSOhoM6aS') format('svg');
    font-weight: normal;
    font-style: normal;

}

@font-face {
    font-family: 'DroidSerif';
    src: url('font/DroidSerif-webfont.eot?') format('eot'),
         url('font/DroidSerif-webfont.woff') format('woff'),
         url('font/DroidSerif-webfont.ttf') format('truetype'),
         url('font/DroidSerif-webfont.svg#webfontw7zqO19G') format('svg');
    font-weight: normal;
    font-style: normal;

}

然后在你的代碼中,你的font-family應該與你在css中聲明的那些相同(即font-family:'Droid Sans';與font-family不同:'DroidSans')

<p style='font-family: "DroidSans",sans-serif;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "DroidSansMono",monospace;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "DroidSerif",serif;'>vând whisky și tequila, preț fix.</p>

試一試,看看你是怎么過的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM