android中使用xml的新自定义字体方法 [英] The new Custom Font Method in android using xml

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

问题描述

当 android 发布其 O 预览版时,添加了一个名为 xml 中的字体 的新功能.它易于实施,但我几乎没有怀疑.

As android released its O preview, a new feature has been added called fonts in xml. Its easy to implement but i have few doubts.

让我先添加最好的方法
1.) 右键单击​​ res 文件夹,然后转到 新建 > Android 资源目录.新的
出现资源目录窗口.
2.)在资源类型列表中,选择字体,然后单击确定.
3.)在字体文件夹中添加你的字体文件.下面的文件夹结构生成 R.font.dancing_script、R.font.la_la 和 R.font.ba_ba.
4.)双击字体文件可在编辑器中预览文件的字体.

let me first add the best way to do it
1.)Right-click the res folder and go to New > Android resource directory. The New
Resource Directory window appears.
2.)In the Resource type list, select font, and then click OK.
3.)Add your font files in the font folder.The folder structure below generates R.font.dancing_script, R.font.la_la, and R.font.ba_ba.
4.)Double-click a font file to preview the file's fonts in the editor.

接下来我们必须创建一个字体系列

Next we must create a font family

1.) 右键单击​​字体文件夹并转到新建 > 字体资源文件.出现新建资源文件"窗口.
2.)输入文件名,然后点击确定.新字体资源 XML 在编辑器中打开.
3.) 将每个字体文件、样式和权重属性包含在字体标签元素中.以下 XML 说明在字体资源 XML 中添加字体相关的属性:

1.)Right-click the font folder and go to New > Font resource file. The New Resource File window appears.
2.)Enter the file name, and then click OK. The new font resource XML opens in the editor.
3.)Enclose each font file, style, and weight attribute in the font tag element. The following XML illustrates adding font-related attributes in the font resource XML:

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <font
    android:fontStyle="normal"
    android:fontWeight="400"
    android:font="@font/hey_regular" />
    <font
    android:fontStyle="italic"
    android:fontWeight="400"
    android:font="@font/hey_bababa" />
</font-family>

向 TextView 添加字体:

Adding fonts to a TextView:

   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    **android:fontFamily="@font/ba_ba"**/>

从文档来看,所有步骤都是正确的.
我的问题是:
1.)这可以在android棒棒糖或棉花糖中使用吗
2.)是否需要任何支持库来实现这些功能
3.)这个支持什么类型的字体扩展,比如.ttf .otf

As from the documentation all the steps are correct.
my question is:
1.)Can this work in android lollipop or marshmallow
2.)Is any support library needed for implementing the features
3.)What type of font extension will this support like .ttf .otf



请给我最好的解释.



Please give me the best explanation.

推荐答案

1.) 这个可以在android lollipop 或 marshmallow 中使用吗

1.)Can this work in android lollipop or marshmallow

回答:它也适用于较低版本(根据我的研究).

Ans : It's work for lower Version also(Based on my research).

2.) 是否需要任何支持库来实现这些功能

2.)Is any support library needed for implementing the features

Ans : 不需要支持 Lib 只需要更新你的 sdk(Android O)

Ans : No need support Lib only you need to update your sdk(Android O)

3.) .ttf .otf 之类的支持什么类型的字体扩展

3.)What type of font extension will this support like .ttf .otf

Ans: 是的,它支持 .ttf, .otf 字体文件.

Ans: Yes, Its support .ttf, .otf font Files.

有关更多信息,您可以查看以下链接:

For more info you can see below links :

字体系列 Api 的 Android 文档 , Android-O 预览视频

这篇关于android中使用xml的新自定义字体方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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