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

送分小仙女□ 提交于 2019-12-24 02:55:08

问题


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.



来源:https://stackoverflow.com/questions/27443363/error-should-use-androidshowasaction-when-not-using-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!