![](/img/trans.png)
[英]“the file name must end with .xml” error for jpg file in Android Studio
[英]Getting error “file name must end with .xml” while using the “android:fontFamily” of Android O?
Android O 引入了一項新功能,即 XML 中的字體,可讓您將字體用作資源。 我正在Android 開發人員提供的資源文件中創建font
文件夾,但問題是我在使用 Android O 版本中提供的font
文件夾時遇到file name must end with .xml
錯誤。
請檢查下面的布局。
<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" />
並請檢查我在res
使用Montserrat_Regular.otf
文件創建的font
文件夾
使用上述方法時出現以下錯誤,具體如下:
我已經搜索過但沒有得到預期的結果,請檢查:
1. 第一個鏈接
2. 第二個鏈接
3. 第三個鏈接
4.第四鏈接
並且Font resource file
沒有創建,因為我正在單擊Right-click the font folder and go to New > Font resource file
。 但是沒有獲得Font resource file
的選項,請檢查以下內容:
Android Studio 2.3.3 構建鏈不完全支持字體資源。 完全支持 Android Studio 3.0+ 及其相關的 Android Plugin for Gradle 版本。 那時,您將能夠創建一個font/
資源目錄,與layout/
、 menu/
等並列。
IOW,在您准備好升級到 Android Studio 3.0 之前,暫緩此操作。
我在這個錯誤上浪費了一個小時,使用 AS 3.0 beta2、Gradle 4.x 和正確的構建工具。
原來我在一個名為“fonts”的文件夾中有一份字體的副本。 此文件夾不會顯示在 Android 項目視圖中。 閱讀錯誤我沒有抓住's'。 只是給各位讀者一個小小的提醒!
我剛剛遇到了同樣的問題,在尋找答案時,我來到了這個線程。 我從deverloper.android.com找到了一個解決方案。
右鍵單擊 Android Studio 中的“res”文件夾
選擇“新建”>“Android 資源目錄”
將其命名為“字體”
您應該在這里放置僅包含az 0-9 和 _ 字符的字體 (.ttf) 文件。
以這種方式設置您的字體(我的稱為“alegreyaregular.ttf”) :
Typeface typeface = ResourcesCompat.getFont(this, R.font.alegreyaregular);
TextView textView.setTypeface(typeface);
我有完全相同的錯誤文件名必須以 .xml 結尾我使用了這些設置並神奇地解決了問題。
在 Project Level Gradle 中使用這些設置:
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.company.app"
minSdkVersion 21
targetSdkVersion 26
...
}
在 Application Level Gradle 中使用這些設置:
classpath 'com.android.tools.build:gradle:3.0.1'
安卓斯蒂迪奧:
Android studio version 3.0.1.
干杯!
我遇到了同樣的問題!! 只需更新您的 build.gradle 文件即可解決上述問題。
compileSdkVersion 26
將您的 AndroidStudio 更新到最新版本。
享受你的一天。
Android Studio 2.4包含對Android O可用的所有新開發人員功能的支持,您需要更新 Studio
並創建XML 文件
1) 右鍵單擊字體文件夾,然后轉到新建 > 字體資源文件。 出現“新建資源文件”窗口。
2) 輸入文件名,然后單擊“確定”。 新字體資源 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/Montserrat_Regular.otf" />
</font-family>
這是一種通用問題,我遇到了錯誤消息
main\\res\\lib\\poi-3.12-android-a.jar: 錯誤:文件名必須以 .xml 結尾
我已經把這個 jar 文件放在資源文件夾(res)中,我刪除了這個 jar 文件和文件夾,它得到了解決。 避免在 res 目錄中出現任何不需要的文件/文件夾。
字體將進入資產文件夾。 右鍵單擊工作室中的app文件夾 - >新建 - >文件夾 - >資源文件夾,然后在資源文件夾中創建一個字體文件夾
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.