Android菜单在错误的地方膨胀

时间:2015-10-11 05:34:51

标签: java android xml menu menuitem

这是我目前的问题:

我的设置菜单错误地膨胀。我不明白为什么,这让我疯了!有没有人知道发生了什么?菜单的位置应略微位于溢出图标下方。它可能是我布置我的标签或浏览器的方式,还是其他的东西?我确定这不是一个孤立的案例,所以如果有人在之前看到过这个问题......

提前致谢!


在我的MainActivity中:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

在我的menu_main.xml中:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:id="@+id/menu_item">
<item android:id="@+id/action_settings"
    android:title="@string/action_settings"
    android:orderInCategory="101"
    app:showAsAction="never" />
<item
    android:id="@+id/action_about"
    android:title="@string/action_about"
    android:orderInCategory="102"
    app:showAsAction="never"/>
</menu>

1 个答案:

答案 0 :(得分:1)

这是默认的UI模式并且不正确,请参考以下official documentation的屏幕截图: enter image description here

如果你不喜欢它,你可以改变这种行为

请参阅this question了解详情。