33

我用AppCompat將我的應用程序移植到API7,並且操作欄出現問題。操作欄未與AppCompat一起顯示

當我使用FragmentActivity時,操作欄顯示在我的手機(API18)上,但是ActionBarActivity通過按menubutton顯示爲選項菜單。

在帶API7的仿真器上,操作欄始終顯示爲選項菜單。

任何想法?

回答

70

使用compat的名稱空間,爲您的菜單項是這樣的:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:compat="http://schemas.android.com/apk/res-auto" > 
    <item android:id="@+id/action_whatever" 
     android:icon="@drawable/ic_action_whatever" 
     android:title="@string/whatever" 
     compat:showAsAction="ifRoom" /> 
</menu> 
6

相關a duplicate that points to this post,我遇到了麻煩,讓我的按鈕顯示爲行動項目,而不是溢出項目,儘管有showAsAction設置爲always。我設法通過將活動擴展爲Activity而不是ActionBarActivity來強制它。根據this answer,這是可以接受的,如果您不需要支持以下11

...extends ActionBarActivity API級別:

extends ActionBarActivity

...extends Activity

enter image description here

0

我與調試Doogee瓦倫西亞Y100Pro,菜單爲「三個小方塊」不可見,但是當我將主動活動擴展爲android.support.v7.app.ActionBarActivity,然後我在操作欄中獲取文本/圖標菜單。 Next screenshot and menu.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <item 
     android:id="@+id/action_update" 
     android:icon="@drawable/ic_refresh" 
     android:title="@string/action_update" 
     app:showAsAction="always"/> 
    <item android:id="@+id/action_settings" 
     android:title="@string/action_settings" 
     app:showAsAction="ifRoom"/> 
</menu>