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

问题描述

像标题所说,我需要使用新的字体。我目前使用Android Studio 2.3.3。



我有一个文件 .ttf(一个字体文件),我想将这个字体添加到res目录(/ res / font )。

我看到其他问题,但是看起来情况有所不同,因为很多人使用Android Studio 3.0。
$ b $所以,对于我们这个贫穷的人来说,这是正确的过程吗? 解决方案

资产目录下放置字体目录,并把 your.ttf 字体文件在这里。



2.您可以更改为此。

  TextView tv =(TextView)findViewById(R.id.tv); 
Typeface tf = Typeface.createFromAsset(v.getContext()。getAssets(),fonts / your.ttf);
tv.setTypeface(tf);

编辑您也可以使用 android:typeface =sans android:typeface =serif android:typeface =monospace在您的xml代码中。 code> android:fontFamily 在xml代码中

从android 4.1 / 4.2 / 5.0开始,下面的字体系列可用:

  android:fontFamily =sans-serif// roboto regular 
android:fontFamily =sans-serif-light// roboto light
android:fontFamily =sans-serif-condensed// roboto condensed
android:fontFamily =sans-serif-black// roboto black
android:fontFamily =sans-serif-thin/ / roboto thin(android 4.2)
android:fontFamily =sans-serif-medium// roboto medium(android 5.0)

同样用于样式

fonts.xml

 <?xml version =1.0encoding =utf-8?> 
<资源>
< string name =font_family_light> sans-serif-light< / string>
< string name =font_family_medium> sans-serif-medium< / string>
< string name =font_family_regular> sans-serif< / string>
< string name =font_family_condensed> sans-serif-condensed< / string>
< string name =font_family_black> sans-serif-black< / string>
< string name =font_family_thin> sans-serif-thin< / string>
< /资源>


like the title says, I need to use a new font. I currently use Android Studio 2.3.3.

I have a file .ttf (a font file) and I would like to add this font in the res directory (/res/font).

I saw other questions, but it seems that things are different because a lot of people use Android Studio 3.0.

So, for us poor people, which is the right process?

解决方案

1.create a new fonts directory in the assets directory and put the your.ttf font file here.

2.You can change to this .

TextView tv = (TextView) findViewById(R.id.tv);
Typeface tf = Typeface.createFromAsset(v.getContext().getAssets(), "fonts/your.ttf");
tv.setTypeface(tf);

Edit

You also can use android:typeface="sans"android:typeface="serif"android:typeface="monospace" in your xml code .

Use android:fontFamily in the xml code

From android 4.1 / 4.2 / 5.0, the following Roboto font families are available:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-black"     // roboto black
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

Also use in the style

fonts.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="font_family_light">sans-serif-light</string>
    <string name="font_family_medium">sans-serif-medium</string>
    <string name="font_family_regular">sans-serif</string>
    <string name="font_family_condensed">sans-serif-condensed</string>
    <string name="font_family_black">sans-serif-black</string>
    <string name="font_family_thin">sans-serif-thin</string>
</resources>

这篇关于在Android Studio 2.3.3中添加字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:23