就像标题所说,我需要使用新字体。我目前使用Android Studio 2.3.3。
我有一个文件.ttf(字体文件),我想将此字体添加到 res 目录 (/res/font) 中。
我看到了其他问题,但情况似乎有所不同,因为很多人使用 Android Studio 3.0。
那么,对于我们穷人来说,哪个才是正确的过程呢?
最佳答案
1.新建fonts
assets
目录中目录并放入 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 代码中。
使用android:fontFamily
在xml代码中
从android 4.1/4.2/5.0开始,以下Roboto可用的字体系列:
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)
也用在样式中
字体.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 - 在Android Studio 2.3.3中添加字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46976269/