如何使用Android的工作室自定义字体 [英] How to use custom font in Android Studio

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

问题描述

我试图用自定义的字体在Android的工作室,因为我们在Eclipse一样。但遗憾的是无法弄清楚哪里放了资产文件夹!

I was trying to use custom font in Android Studio as we did in Eclipse. But unfortunately could not figure out where to put the 'assets' folder!

推荐答案

下面是几个步骤来解决它:

Here is the few steps to solve it:

  1. 转到(项目文件夹)
  2. 应用程序>来源>主
  3. 创建文件夹的资产>字体主要文件夹。
  4. 把你的'abc.ttf到字体文件夹。

  1. Go to the (project folder)
  2. Then app>src>main
  3. Create folder 'assets>fonts' into the main folder.
  4. Put your 'abc.ttf' into the fonts folder.

    AssetManager am = context.getApplicationContext().getAssets();

    typeface = Typeface.createFromAsset(am,
            String.format(Locale.US, "fonts/%s", "abc.ttf"));

    setTypeface(typeface);

或尝试这种方式:

or try this way:

   TextView tx = (TextView)findViewById(R.id.textview1);

   Typeface custom_font = Typeface.createFromAsset(getAssets(),  "fonts/abc.ttf");

   tx.setTypeface(custom_font);

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

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