Error : should use android:showAsAction when not u

2019-07-11 09:26发布

问题:

I'm using app compact support library v7 for providing support of lollipop in my app. I was able to make it work perfectly. When my actionbar not showing menu items as icon.

I have followed this link to make it work .
Following is my menu.xml :

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


<item
    android:id="@+id/contact_add"
    android:icon="@drawable/ic_btn_add_contact"
    android:title="@string/add" 
    app:showAsAction="always"/>
<item
    android:id="@+id/contact_delete"
    android:icon="@drawable/ic_btn_add_contact"
    android:showAsAction="never"
    android:title="@string/delete"/>
</menu>

Still I am getting following error : should use android:showAsAction when not using appcompat library

What am I doing wrong ???

回答1:

Update your Menu Bar with this code

<menu xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:android="http://schemas.android.com/apk/res/android" ><item
android:id="@+id/contact_add"
android:icon="@drawable/ic_btn_add_contact"
android:title="@string/add" 
app:showAsAction="always"/><item
android:id="@+id/contact_delete"
android:icon="@drawable/ic_btn_add_contact"
app:showAsAction="never"
android:title="@string/delete"/></menu>

You are getting the error because you are using

android:showAsAction="never"

You are supposed to write it as

app:showAsAction="never"


回答2:

I solved this in following manner :

Go to Build Path/Configure Build Path and on the Order and Export tab,

check the support jars and uncheck Android Dependencies. 

Do this for support library android-support-v7-appcompat also. Then just clean your project and error is solved.

Here is the link from where I get this.