[英]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.你可以为错误做两件事。
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
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.