我可以在 Android 应用程序中嵌入自定义字体吗? [英] Can I embed a custom font in an Android application?

查看:19
本文介绍了我可以在 Android 应用程序中嵌入自定义字体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个应用程序包含一个用于呈现文本的自定义字体,加载它,然后将它与像 StaticText 这样的标准元素一起使用.这可能吗?

I would like to have an app include a custom font for rendering text, load it, and then use it with standard elements like StaticText. Is this possible?

推荐答案

是的,你可以,你只是不能将它定义到 xml 布局中.您每次都需要动态使用它.例如,查看本教程.

Yes you can, you jsut can't define it into xml layouts. You need to use it dynamically each time. Check this tutorial for instance.

如果链接失效了,这里总结一下:

In case link is dead, here is a sum up of the stuff :

  • 获取类似times.otf
  • 的字体文件
  • 将其拖放到您的资产文件夹中的字体"文件夹中
  • 使用类似的东西获取对 TextView 的引用:

  • Get a font file like times.otf
  • Drop it in your asset folder, inside a "fonts" folder
  • Get a reference of TextView with something like that:

TextView tv = (TextView) findViewById(R.id.myCustomTVFont);

  • 从资产文件夹中获取字体:

  • Grab you font from the asset folder:

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/times.otf");
    

  • 让你的 TextView 看起来很棒:

  • Make your TextView look great:

    tv.setTypeface(tf);
    

  • 这篇关于我可以在 Android 应用程序中嵌入自定义字体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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