操作按钮在Android操作栏中显示但不显示溢出菜单

时间:2014-09-01 12:35:17

标签: android android-actionbar

我是一名新开发人员并尝试显示操作按钮和溢出菜单。 4/6按钮显示在actionBar但我看不到溢出菜单与其他按钮。以下是代码

res / menu / menu / menu_activity_action.xml

<menu  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res-auto" >
    <item
        android:id="@+id/phone"
        android:title="@string/phone"
        android:icon="@drawable/phone"
        and
        myapp:showAsAction="ifRoom|withText"
    />

    <item
        android:id="@+id/computer"
        android:title="@string/computer"
        android:icon="@drawable/computer"
        myapp:showAsAction="ifRoom|withText"
    />

    <item
        android:id="@+id/gamepad"
        android:title="@string/gamepad"
        android:icon="@drawable/gamepad"
        myapp:showAsAction="ifRoom|withText"
    />

    <item
        android:id="@+id/camera"
        android:title="@string/camera"
        android:icon="@drawable/camera"
        myapp:showAsAction="ifRoom|withText"
    />

    <item
        android:id="@+id/video"
        android:title="@string/video"
        android:icon="@drawable/video"
        myapp:showAsAction="ifRoom|withText"
    />

    <item
        android:id="@+id/email"
        android:title="@string/email"
        android:icon="@drawable/email"
        myapp:showAsAction="ifRoom|withText"
    />
</menu>

mainActivity:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_activity_action,menu);
        return super.onCreateOptionsMenu(menu);
    }

任何想法?

2 个答案:

答案 0 :(得分:0)

尝试更改为:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_activity_action, menu);

    return true;
}

答案 1 :(得分:0)

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_activity_action, menu);
    return true;
}