`
WinLi
  • 浏览: 49193 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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")为字体文件路径。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics