简体   繁体   English

android工作室。 错误:文件名必须以.xml结尾

[英]android studio. Error: The file name must end with .xml

I am trying to add icons on the action bar of my app, so I have imported an icon(.png) in the drawable folder but there is an error saying that the file name must end with.xml我正在尝试在我的应用程序的操作栏上添加图标,因此我在可绘制文件夹中导入了一个图标(.png),但出现错误提示文件名必须以 .xml 结尾

The following is my xml code:以下是我的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <item android:id="@+id/action_create_order"
        android:title="@string/action_create_order"
        android:icon="@drawable/ic_action_name"
        android:orderInCategory="1"
        app:showAsAction="always">
    </item>

    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />
</menu>

The error is coming for the first item(ic_action_name).第一项 (ic_action_name) 出现错误。

You need use vector instead image on drawble folder 您需要使用vector代替drawble folder image

Try the sample as follow on your drawable/ic_menu_camera.xml : 在您的drawable/ic_menu_camera.xml上尝试以下示例:

ic_menu_camera.xml ic_menu_camera.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24.0"
    android:viewportWidth="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
    <path
        android:fillColor="#FF000000"
        android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
</vector>

You can do two things for the error.你可以为错误做两件事。

  1. Check the place where it is showing error and see if you have any files which does not have.xml as extension and then press Shift+F6 (on Windows) to rename and add.xml检查显示错误的地方,看看是否有任何文件没有 .xml 作为扩展名,然后按 Shift+F6(在 Windows 上)重命名并添加 .xml

  2. If you don't see any files not having.xml extension then just go to File -> Invalidate Caches and Restart如果您没有看到任何没有 .xml 扩展名的文件,那么只需 go 到 File -> Invalidate Caches and Restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Studio 中 jpg 文件的“文件名必须以 .xml 结尾”错误 - “the file name must end with .xml” error for jpg file in Android Studio Android Studio 文件名必须以.xml结尾 - Android Studio File name must end with .xml ! 错误。 文件名必须以 xml 结尾 - ! Error. The file name must end with xml 错误:文件名必须以 .xml 或 .png 结尾 - Error: The file name must end with .xml or .png 使用Android O的“android:fontFamily”时出现错误“文件名必须以.xml结尾”? - Getting error “file name must end with .xml” while using the “android:fontFamily” of Android O? Android:在res中使用SVG会导致错误:“文件名必须以.xml或.png结尾” - Android: Using SVG in res leads to error: “The file name must end with .xml or .png” 反应原生。 错误:文件名必须以 .xml 或 .png 结尾 - React Native. Error: The file name must end with .xml or .png 错误:使用.png时文件名必须以.xml或.png结尾 - Error: The file name must end with .xml or .png when using .png itextpdf-5.5.6.jar:错误:文件名必须以.xml结尾 - itextpdf-5.5.6.jar: Error: The file name must end with .xml 在Android Studio中使用SlidingMenu make应用程序时出错。 二进制XML文件第2行:错误放大类片段 - something error to using SlidingMenu make application in android studio. Binary XML file line #2: Error inflating class fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM