Android 添加设置自定义字体

把字体文件放到Asset/font目录下

Typeface typeFace = Typeface.createFromAsset(mContext.getAssets(), "font/fzktjt.ttf");
TextView.setTypeface(typeFace);

如果是设置网页的字体,使用WebView渲染,则需要修改网页代码

例如

<html>
<head>
<style type="text/css">
@font-face {
    font-family: MyFont;
    src: url("file:///android_asset/font/fzktjt.ttf")
}
body {
    font-family: MyFont;
    font-size: medium;
    text-align: justify;
}
</style>
</head>
<body>
Your text can go here! Your text can go here! Your text can go here!
</body>
</html
 其中 src: url("file:///android_asset/font/fzktjt.ttf")为字体文件路径。

相关推荐