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.
I've lost an hour on this error, using AS 3.0 beta2, Gradle 4.x and the correct build-tools.
Turned out I had a copy of the fonts in a folder called "fonts". This folder doesn't show up in the Android project view. And reading the error I didn't catch the 's'. Just a small reminder for you readers!
I just had the same problem and while searching for an answer, I came here on this thread. I've found a solution from deverloper.android.com .
Right click 'res' folder in Android Studio
Choose 'new' > 'Android resource directory'
Name it 'font'
Inhere you should place your font (.ttf) files WITH ONLY az 0-9 and _ characters.
Set your font (mine is called 'alegreyaregular.ttf') this way:
Typeface typeface = ResourcesCompat.getFont(this, R.font.alegreyaregular);
TextView textView.setTypeface(typeface);
I had exactly same error file name must end with .xml I used these settings and problem magically resolved.
Use these setting in Project Level Gradle :
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.company.app"
minSdkVersion 21
targetSdkVersion 26
...
}
Use these setting in Application Level Gradle :
classpath 'com.android.tools.build:gradle:3.0.1'
Android Stidio :
Android studio version 3.0.1.
Cheers!
I had faced same problem!! Just update your build.gradle file to resolve above issue.
compileSdkVersion 26
Update your AndroidStudio to latest vetsion.
Enjoy your day.
Android Studio 2.4 includes support for all the new developer features available with Android O you need to update studio
And create XML file
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.
<?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/Montserrat_Regular.otf" />
</font-family>
This is kind of generic issue and I faced this one with error message
main\\res\\lib\\poi-3.12-android-a.jar: Error: The file name must end with .xml
I had placed this jar file inside resource folder(res), I removed this jar file and folder it get resolved. Avoid any unwanted files/folder inside res directory.
Fonts will go in the asset folder. Right click app folder in your studio -> New -> Folder -> Assets Folder, and the make a font folder in the assets folder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.