出现错误“文件名必须以.xml结尾"在使用"android:fontFamily"时的Android O? [英] Getting error "file name must end with .xml" while using the "android:fontFamily" of Android O?

查看:45
本文介绍了出现错误“文件名必须以.xml结尾"在使用"android:fontFamily"时的Android O?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android O引入了一项新功能,即XML中的字体,可让您将字体用作资源.而且我正在由

使用上述方法时出现以下错误:

我已经搜索过,但是没有得到预期的结果,请检查:

解决方案

Android Studio 2.3.3构建链不完全支持字体资源.全面支持Android Studio 3.0+及其相关的Android Plugin for Gradle版本.到那时,您将能够创建一个 font/资源目录,该目录与 layout/ menu/等一起出现.

IOW,请不要执行此操作,直到准备好升级到Android Studio 3.0.

Android O introduces a new feature, Fonts in XML, which lets you use fonts as resources. And I am creating the font folder in resource file as it provided by Android developer, but the problem is that I am getting error that file name must end with .xml while using the font folder which is provided in Android O release.

Please check the below layout for it.

 <TextView
   android:id="@+id/txtMsgCount"
   android:layout_width="wrap_content"
   android:layout_height="16dp"
   android:background="@drawable/msg_count"
   android:gravity="center"
   android:text="123"
   android:fontFamily="@font/Montserrat_Regular" ////IT IS MY FONT STYLE
   android:textColor="@android:color/white"
   android:textSize="10sp" />

And please check the font folder which I have created in res with Montserrat_Regular.otf file

I am getting the following error while using the above, which are as follows:

I have searched about it but did not get expected result, please check:

1. First Link
2. Second Link
3. Third Link
4. Forth Link

And the Font resource file is not creating as I am clicking the Right-click the font folder and go to New > Font resource file. But not getting the option of the Font resource file, please check below:

解决方案

Font resources are not fully supported by the Android Studio 2.3.3 build chain. Full support comes with Android Studio 3.0+ and its associated Android Plugin for Gradle version. At that point, you will be able to create a font/ resource directory that goes alongside layout/, menu/, etc.

IOW, hold off on this until you are ready to upgrade to Android Studio 3.0.

这篇关于出现错误“文件名必须以.xml结尾"在使用"android:fontFamily"时的Android O?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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