Question

I'm getting a weird issue, i'm using appcompatv7 in Android Studio, I have a menu which contains this,

     <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.itspirits.LifeEncyclopediaAdv.lifeencyclopedia.activities.MainScreenActivity" >

    <item android:id="@+id/action_share"
        android:icon="@drawable/share"
        android:showAsAction="ifRoom"
        android:title="Share"/>
</menu>

Yet, the icon is never appearing, but it is only shown in a menu. It is not a problem of room because there is no icon and far enough room on the actionbar. Any suggestion why this problem.

Était-ce utile?

La solution

As stated in the Action Bar Guide, the android:showAsAction will only apply to v11+ devices - you need to use app:showAsAction to have it display in the Action Bar for all appcompat compatible Android versions:

<item android:id="@+id/action_share"
    android:icon="@drawable/share"
    app:showAsAction="ifRoom"
    android:title="Share"/>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top