6

我在使用 AppCompat 在 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>

但是对于 AppCompat 库,该项目未显示..

我应该怎么办 ?

提前致谢 :)

4

1 回答 1

42

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

于 2013-08-22T17:13:16.413 回答