Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error "file name must end with .xml" while using the "android:fontFamily" of Android O?

Tags:

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

My font folder with font style

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

Error getting

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:

enter image description here

like image 422
Ravindra Kushwaha Avatar asked Aug 11 '17 10:08

Ravindra Kushwaha


People also ask

What is the default font family in Android?

"Roboto and Noto are the standard typefaces on Android and Chrome." From Wiki, "Roboto is a sans-serif typeface family developed by Google as the system font for its mobile operating system Android."


1 Answers

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.

like image 193
CommonsWare Avatar answered Sep 20 '22 16:09

CommonsWare