java - Android 菜单在错误的地方膨胀

标签 java android xml menu menuitem

这是我目前的问题:

我的设置菜单膨胀不正确。我不知道为什么,这让我发疯!有没有人知道发生了什么事?菜单的位置应该稍微在溢出图标下方。可能是我布置选项卡或 viewpager 的方式,还是其他原因?我敢肯定这不是一个孤立的案例,所以如果有人以前见过这个问题......

提前致谢!


在我的 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>

最佳答案

这是默认的 UI 模式,并没有错,请引用以下来自 official documentation 的屏幕截图: enter image description here

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

引用this question了解详情。

关于java - Android 菜单在错误的地方膨胀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33061893/

相关文章:

android - 从数据库中提取的多级 ListView

android - 在用户触摸 MapView Android 上返回 GeoPoint

安卓 7.0 : install . apk

xml - WSO2 使用 xpath 获取 xml-content 属性中的元素

Android Play 报亭布局设计

javascript - 我必须将我想要在 Eclipse 上的动态 Web 项目中使用的 xml 文件放在哪里?

java - 是否可以将函数作为枚举构造函数参数?

java - 使用数组并对元素求和

java - 如何在 Windows 上的 jenkins 中编译和运行一个简单的 java 文件

java - 使用 Apache Tiles 时 Struts2 中的命名空间问题