难道我们必须复制字体TTF每次我们要改变字体的应用 [英] Do we have to copy Font TTF everytime we want to change font in application

查看:119
本文介绍了难道我们必须复制字体TTF每次我们要改变字体的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

previously,使我的应用程序可行的姜饼器件及以上的,我必须将Robotto字体资源复制到资源文件夹。这是因为姜饼没有附带Robotto字体本身。

不过,让说,我决定部署我的应用程序果冻豆的设备而已。

  1. 请我仍然需要的字体资源手动复制到我的资源文件夹?我是否可以使用字体资源系统本身?它说的是鼓励,能?我在想,不提供我自己的字体文件,我可以让我的应用程序更小。
  2. 这是在code获得字体从资源文件夹。

    字样TF = Typeface.createFromAsset(getAssets(),字体/ Roboto-Regular.ttf);

    如果我想获得字体直接从系统本身,怎么样?

解决方案

好消息是,如果你支持4.1,它是死的简单。请查看此链接,然后向下滚动到字体的全部细节,但基本上,你马上有三种字体系列(Roboto,Roboto光,RobotoCondensed)可供选择,和四种风格为每一个(正常,粗体,斜体,粗斜体)。

在XML中,你可以使用标准的文本属性:

 安卓fontFamily中=无衬线
机器人:fontFamily中=无衬线光
机器人:fontFamily中=无衬线,凝聚

机器人:TEXTSTYLE =黑体
机器人:TEXTSTYLE =斜体
机器人:TEXTSTYLE =黑体|斜体
 

或者编程,你可以获取他们像这样:

 字样robotoLightItalic = Typeface.create(无衬线光,Typeface.ITALIC);
 

Previously, to make my app workable in Gingerbread device and above, I have to copy the Robotto font resource into asset folder. This is because Gingerbread doesn't come with Robotto font itself.

However, let say, I decide to deploy my app to Jelly Bean device only.

  1. Do I still need to copy font resources into my asset folder manually? Can I use font resources from system itself? Is it something encourage-able? I was thinking, without supplying my own font files, I can make my app smaller.
  2. This is the code to get TypeFace from asset folder.

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");

    If I want to get TypeFace directly from system itself, how?

解决方案

The good news is, if you're supporting 4.1, it's dead simple. Check out this link and scroll down to fonts for the full details, but basically, you'll have three font families (Roboto, Roboto Light, RobotoCondensed) to choose from, and four styles for each (normal, bold, italic, bold italic).

In XML, you can just use the standard text attributes:

android:fontFamily="sans-serif"
android:fontFamily="sans-serif-light"
android:fontFamily="sans-serif-condensed"

android:textStyle="bold"
android:textStyle="italic"
android:textStyle="bold|italic"

Or programatically you can acquire them like so:

Typeface robotoLightItalic = Typeface.create("sans-serif-light", Typeface.ITALIC);

这篇关于难道我们必须复制字体TTF每次我们要改变字体的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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