【问题标题】:No resource identifier found for attribute 'id' and 'order in category' in package 'android'在包'android'中找不到属性'id'和'order in category'的资源标识符
【发布时间】:2015-01-08 08:05:32
【问题描述】:

我的 menu.xml 文件中出现此错误。这很奇怪,因为我已经多次检查了我的代码。我已经尝试清理和重命名 id 但没有效果,并且还尝试构建项目但由于此错误而没有构建项目任何人都可以帮助我解决这个问题。我已经尝试过不同的问题,但没有找到答案。这是我的代码 我也尝试了这个问题中给出的解决方案,但没有用: No resource identifier found for attribute 'showAsAction' in package 'android'

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/action_add_new_alarm"     //error is here.
    android:icon="@drawable/action_bar_add"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"        //error is here
    android:title="" />

<!--&lt;!&ndash;&ndash;&gt;-->
</menu>

我得到的错误是这个

Error:(3) No resource identifier found for attribute 'id' in package 'com.xxx.xxxxx'
Error:(3) No resource identifier found for attribute 'orderInCategory' in package '

还有一件事我正在使用 android studio。

【问题讨论】:

    标签: android android-xml android-menu


    【解决方案1】:

    您应该将“android:showAsAction”更改为“app:showAsAction”,如下所示:

    <?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"> //Then you can use this
        <!-- Search, should appear as action button -->
        <item android:title="@string/action_search"
            android:id="@+id/action_search"
            android:icon="@drawable/ic_action_search"
            app:showAsAction="ifRoom"/>   //change android: to app:
    
        <!-- Settings, should always be in the overflow -->
        <item android:id="@+id/action_settings"
            android:title="@string/action_settings"
            app:showAsAction="never" />   //change android: to app:
    </menu>
    

    这对我有用

    【讨论】:

      【解决方案2】:

      改变

      <menu xmlns:android="http://schemas.android.com/apk/res-auto"> 
      

      <menu xmlns:android="http://schemas.android.com/apk/res/android" >
      

      它应该可以工作。

      【讨论】:

      • 然后我在 showAsAction 中收到错误说我应该使用 schemas.android.com/apk/res-auto ?
      • 它也适用于我 showAsAction。你能告诉我你的最小和最大 sdk 版本
      • 我正在使用 min sdk 11 和 max 19。当我同时使用 res-auto 和 android 时,它会给出错误 Error:(3) Error parsing XML: duplicate attribute
      • 虽然您的回答帮助我解决了问题,但我仍然面临 showAsAction 中的错误。
      • stackoverflow.com/questions/5260686/… 参考一次并尝试同时添加 'schemas.android.com/apk/res/android" xmlns:yourapp="schemas.android.com/apk/res-auto" > '
      猜你喜欢
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多