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

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

问题描述

Android发布O预览版后,新增了一项名为字体的新功能。它很容易实现,但我有一些怀疑。

让我先添加最好的方法来做到这一点 -
1)右键单击 res文件夹,然后转到新建> Android资源目录。将显示新建
资源目录窗口。

2.)在资源类型列表中,选择字体,然后单击确定。

3。)将字体文件添加到字体文件夹中。下面的文件夹结构生成R.font.dancing_script,R.font.la_la和R.font.ba_ba。

4。)双击字体文件在编辑器中预览文件的字体。



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



<1>)右键单击字体文件夹并转到新建>字体资源文件。出现新建资源文件窗口。

2.)输入文件名,然后单击确定。新的字体资源XML将在编辑器中打开。

3.)在字体标签元素中包含每个字体文件,样式和重量属性。以下XML说明了在字体资源XML中添加与字体相关的属性:

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

将字体添加到TextView中:

<$ p
$ b $ android
$ android

$ android $ {
$ b $ android $ {
$} android:fontFamily =@ font / ba_ba ** />

从文档的所有步骤都是正确的。我的问题是:

1.)这可以在Android棒棒糖或棉花糖

工作2.)是否需要任何支持库实现功能

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






请给我最好的解释。 1)可以在android棒棒糖或棉花糖中工作



Ans :这对于较低版本也是有效的(基于我的研究)。
$ b 2)是否需要任何支持库来实现这些功能?

答案:不需要支持只有你需要更新你的sdk(Android O)
$ b $ 3.这种支持什么类型的字体扩展.ttf .otf


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



info你可以看到下面的链接:



/www.youtube.com/watch?v=63pKwVE4Uogrel =nofollow noreferrer> Android-O预览视频


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.

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.)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>

Adding fonts to a TextView:

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

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.)Can this work in android lollipop or marshmallow

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

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

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

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

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

For more info you can see below links :

Android Doc for Font Family Api , Android-O Preview Video

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

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