Android Studio错误:无法解析Xml中的符号 [英] Android Studio error: cannot resolve symbol in Xml
问题描述
我正在关注Google Android Studio的第一个android应用程序教程.但是,当我尝试向我的应用添加搜索栏时,出现了3个奇怪的错误.
I'm following the google Android Studio first android app tutorial. But I get 3 weird errors now when trying to add a search bar to my app.
我现在在这里,并且像本教程一样添加了XML代码.
I'm here right now and I added the XML code just like the tutorial.
http://developer.android.com/training/basics/actionbar/adding-buttons.html
我得到的错误:
Error:(5, 23) No resource found that matches the given name (at 'icon' with value '@drawable/ic_action_search').
Error:(6, 24) No resource found that matches the given name (at 'title' with value '@string/action_search').
在android:showAsAction ="ifRoom"上,我遇到了奇怪的错误:
At android:showAsAction="ifRoom" I'm getting the weird error:
Excecution failed for task ':app:procesDebugResources'.
这是我的XML代码:
<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_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom" />
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
此代码有什么问题?
感谢您的阅读/帮助!
推荐答案
尝试一下:
<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_search"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/action_search"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
一些注意事项:
1)您应该将android:showAsAction标记更改为app:showAsAction,这与与旧版android的兼容性有关.
1) You should change android:showAsAction tag to app:showAsAction, this is to do with compatibility with older versions of android.
2)我已将您的搜索图标更改为嵌入Android的图标.您正在做的是尝试使用本机Android图标.自从您的教程以来,这种情况似乎已经改变.您始终可以使用自己的图标,并将其放在项目的res/drawable文件夹中.
2) I've changed your search icon to one embedded in Android. What you're doing is trying to use a native Android icon. Seems like this has changed since your tutorial. You can always use your own icon and put it in the res/drawable folders in your project.
3)就像@drawable是对您的可绘制对象的引用一样,@ string是对res/values文件夹中的strings.xml文件的引用.您需要打开此xml文件并添加以下内容:
3) Just as @drawable is a reference to your drawables, @string is a reference to the strings.xml file in your res/values folder. You need to open this xml file and add something like:
<string name="action_search">Search</string>
希望如此,祝您好运.
这篇关于Android Studio错误:无法解析Xml中的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!