不能证明与AppCompat库项目项目、AppCompat

2023-09-04 11:37:06 作者:人从了心就怂了

我有一些麻烦,以显示与AppCompat的动作条的项目。

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

这code工作在一个正常的动作条​​

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>

但随着AppCompat库中的项目不显示。

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

我应该怎么办?

在此先感谢:)

推荐答案

showAsAction 不是在android XML命名空间API&LT; 11尝试类似如下:

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>

请注意,我已经增加的xmlns:yourapp =htt​​p://schemas.android.com/apk/res-auto 菜单中的属性和改变的空间 showAsAction 机器人 yourapp 。

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.

更多阅读这里:http://developer.android.com/guide/topics/ui/actionbar.html