1

Hello

I'm trying to add 2 menu items in the action bar. On the designer they look ok, but when I run the application, both menu items goes in the dropdown list hamburger menu (there's enough "room" to display on the action bar).

I tried to replace app:showAsAction to android:showAsAction, doesn't work this replacement.

this is my 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" />

And this is the java code:

 @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;
}

Thanks in advance (P.S. Logo doesn't load on Logout menu Item)

Sreehari
  • 5,621
  • 2
  • 25
  • 59
Vlad Marinescu
  • 75
  • 1
  • 1
  • 8
  • Try setting `orderInCategory` for your items. Documentations states that most important items are show as action, and it may be that without the attribute, your items has no importance at all. – Marius Kaunietis Feb 01 '16 at 09:50

1 Answers1

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. 
HourGlass
  • 1,805
  • 1
  • 15
  • 29