Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : should use android:showAsAction when not using support library

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

like image 680
uniruddh Avatar asked Jun 13 '26 11:06

uniruddh


2 Answers

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"
like image 83
Ahmed Raza Avatar answered Jun 18 '26 00:06

Ahmed Raza


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.

like image 42
uniruddh Avatar answered Jun 17 '26 23:06

uniruddh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!