在Android的自定义字体 [英] Custom Fonts in Android

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

问题描述

我已经读了一些文章和搜索谷歌,但我没能做到这一点。

I have already read some articles and searched on Google, but I failed to do it.

我的问题是关于字体面。

My problem is regarding the font-face.

在Android中,只有4属性安卓字体:正常,三世,衬线,等宽

In Android, there are only 4 attributes in "android:typeface": Normal, Sans, Serif, Monospace.

那么,做我必须做使用宋体,在我的应用程序?

So what do I have to do to use "Verdana" in my application?

请建议我使用这个字体在我的Andr​​oid应用程序的正确道路。

Please suggest me a correct way to use this font in my Android application.

推荐答案

这是一个简单的例子......在你的项目中称为根目录下创建一个文件夹资产/字体/ 然后粘贴TTF字体文件(在这种情况下Verdana.ttf)。然后,如果你要的字体应用到,说的TextView ,请执行以下操作:

This is a simple example... create a folder in the root of your project called assets/fonts/ then paste the TTF font file (in this case Verdana.ttf). Then, if you want to apply that font to, say a TextView, do the following:

import android.graphics.Typeface;

public class FontSampler extends Activity {
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    TextView tv=(TextView)findViewById(R.id.custom);
    Typeface face=Typeface.createFromAsset(getAssets(),
                                          "fonts/Verdana.ttf");

    tv.setTypeface(face);
  }
}

这个例子是取自ComonsWare书(作者马克·墨菲)。您可以从GitHub的下载完整的例子。

This example was taken from the ComonsWare book (written by Mark Murphy). You can download the full example from GitHub.

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

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