2

I am getting this error in my menu.xml file. this is odd since I have checked my code many times. I have tried cleaning and renaming the the id but no effect and also tried to build the project but project didn't build due to this error can anybody help me with this. I have tried different questions already but didn't found the answer. here is my code I have also tried the solutions given in this question but no use: 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>

and the error I am getting is this

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 '

And one more thing I am using android studio.

Community
  • 1
  • 1
Umair
  • 6,366
  • 15
  • 42
  • 50

2 Answers2

7

You should change "android:showAsAction to "app:showAsAction as per below:

<?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>

This worked for me

0110100110
  • 126
  • 2
  • 5
2

change the

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

to

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

it should works.

RamBabu Pudari
  • 912
  • 7
  • 19
  • then I get the error in showAsAction saying I should use http://schemas.android.com/apk/res-auto ? – Umair Jan 08 '15 at 08:14
  • its works for me showAsAction also.can u tell me your min and max sdk verion – RamBabu Pudari Jan 08 '15 at 08:18
  • I am using min sdk 11 and max 19. and when I use both res-auto and android it gives error Error:(3) Error parsing XML: duplicate attribute – Umair Jan 08 '15 at 08:56
  • although your answer helped me solve the problem but still I am facing the error in showAsAction. – Umair Jan 08 '15 at 09:16
  • http://stackoverflow.com/questions/5260686/no-resource-identifier-found-for-attribute-showasaction-in-package-android refer this once and try to add both ' ' – RamBabu Pudari Jan 08 '15 at 09:25
  • Thanks alot change the name from android to myappname solved the problem ... :) – Umair Jan 08 '15 at 09:30