I have a weird problem, I was using a menu.xml file in my android application like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_refresh"
android:orderInCategory="100"
android:title="@string/action_refresh"
android:icon="@drawable/toc"
compat:showAsAction="always"/>
</menu>
and it was working well, but some days ago i was updating my eclipse to the last version, and after that, the app:showAsAction="always" shows the error:
Should use android:showAsAction when not using the appcompat library and after that my action bar icons was moved to the overflow bar and not showing the in the action bar at all.
anyway, the appcompat library is the parent of my base style. what should I do to resolve that?
You need to do three things-
Add these 3 things xmlns:tools="schemas.android.com/tools"
tools:context="com.example.sample.YourActivity" xmlns:yourapp="http://schemas.android.com/apk/res-auto"
to your <menu>
tag
along with the usual xmlns:android="http://schemas.android.com/apk/res/android"
Add yourapp:showAsAction="ifRoom"
to your <item>
.
Finally, clean your project via Project -> Clean...
The last step is what solved it for me. Simply cleaning the project (they can get so dirty sometimes)
This is what the final code looks like:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="schemas.android.com/tools"
tools:context="com.example.sample.YourActivity"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_share"
android:orderInCategory="100"
android:title="Share"
android:icon="@drawable/ic_share_white"
yourapp:showAsAction="ifRoom" />
</menu>
This works for me i have used appcompatlibrary:
compat:showAsAction="always"
instead of:
app:showAsAction="always"
And to use compat:showAsAction="always" , inside menu.xml include the line:
<menu
......
<!-- include the below line -->
xmlns:compat="http://schemas.android.com/apk/res-auto" >
Faced the same problem. These two options worked for me:
1.Including - xmlns:compat="http://schemas.android.com/apk/res-auto" > and then using:"compat:showAsAction="ifRoom"/>"
2.Not including the compat and simply using: app:showAsAction="ifRoom"/>
PS: Using Android Studio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With