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

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

问题描述

我想有一个应用程序,包括自定义字体渲染文本,加载它,然后使用它像静态文本标准元素。这可能吗?

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天全站免登陆