Couldn't show items with AppCompat library

爷,独闯天下 提交于 2019-12-29 07:43:09

问题


I am having some troubles to show items in the ActionBar with AppCompat.

This code works on a normal actionbar

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/item1"
        android:showAsAction="always"
        android:title="Se connecter"
        android:visible="true">
    </item>

</menu>

But with the AppCompat library the item isn't shown..

What should I do ?

Thanks in advance :)


回答1:


showAsAction is not in the android xml namespace for API < 11 try something like the following:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:yourapp="http://schemas.android.com/apk/res-auto">

<item android:id="@+id/action_refresh"
    android:title="@string/refresh"
    yourapp:showAsAction="always"
    android:icon="@drawable/ic_action_refresh" />
</menu>

Note that I've added xmlns:yourapp="http://schemas.android.com/apk/res-auto in menu attributes and changed the namespace of showAsAction from android to yourapp.

More reading here: http://developer.android.com/guide/topics/ui/actionbar.html



来源:https://stackoverflow.com/questions/18386642/couldnt-show-items-with-appcompat-library

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