开发者

How does one change fonts in web pages for Android?

I'm making a simple browser based game using Javascript and HTML4. I have a single page and only two or three text blocks, so I want to avoid a separate style sheet if possible. I am happy to use Android's built in "Droid Serif" But Android ignores this and always defaults to "Droid Sanserif".

Stacoverflow has plenty of advice on adding custom fonts, but I can't find anything on accessing built in fonts.

I define the font-family within a div that surrounds the text. I tried posting the HTML here, but stackoverflow interprets it as formatting and just shows the result, not开发者_JAVA百科 the code.

My html works fine in all regular browsers, and works fine in Android if I use Google's online fonts, so the structure of the HTML must be fine. But "Droid Serif" and all other font instructions are ignored. Any ideas how to make it behave?


I am assuming you mean that you have a local font file on the device and want to access it through a WebView? The best way is through a ContentProvider, it can serve local assets to a webview including fonts. Here's how to setup the ContentProvider: http://responsiveandroid.com/2012/02/20/serving-android-webview-resources-with-content-providers.html . There are example there for javascript, image files and css files. Following the structure from the tutorial, to get a font you would use something like

@font-face {
    font-family: MyFont;
    src: url("content://com.github.browep.lfcp/MyFont.ttf")
}

and it would be served from the local filesystem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜