安卓开发使用ttf文字_在android中使用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.

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:

android:fontStyle="normal"

android:fontWeight="400"

android:font="@font/hey_regular" />

android:fontStyle="italic"

android:fontWeight="400"

android:font="@font/hey_bababa" />

Adding fonts to a 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 :

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值