菜单项位于下拉列表菜单中,而不在操作栏中

时间:2016-02-01 09:42:41

标签: android android-menu

你好

我正在尝试在操作栏中添加2个菜单项。在设计师看来他们看起来还不错,但是当我运行应用程序时,两个菜单项都会进入下拉列表汉堡包菜单(有足够的“空间”显示在操作栏上)。

我尝试将app:showAsAction替换为android:showAsAction,但无法替换此版本。

这是我的 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="com.tabdemo.MainActivity">

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:title=""
    app:showAsAction="never"
    />
<item
    android:id="@+id/userMenu"
    android:title="User"
    app:showAsAction="ifRoom" />
<item
    android:id="@+id/logoutMenu"
    android:icon="@drawable/opendoorlogo2"
    android:title="Logout"
    app:showAsAction="ifRoom" />

这是java代码:

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    MenuItem userMenuItem = menu.findItem(R.id.userMenu);
    userMenuItem.setTitle(username);// global string
    MenuItem logoutMenuItem = menu.findItem(R.id.logoutMenu);
    logoutMenuItem.setIcon(R.drawable.opendoorlogo2);
    return true;
}

提前致谢(P.S.徽标未在Logout菜单项上加载)

1 个答案:

答案 0 :(得分:0)

    First of all make sure your drawable file is not too big for the actionbar, if so you can convert it to actionbar icon size. 

https://romannurik.github.io/AndroidAssetStudio/icons-actionbar.html#source.space.trim=1&source.space.pad=0&name=ic_action_example&theme=light&color=33b5e5%2C60

android:showAsAction="always"

    if this doesn't help you. 

    Best way is to create a custom actionbar layout and place your icon over there instead of adding it as Menus.