문제

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.

도움이 되었습니까?

해결책

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"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top