Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Items in ActionBarCompat are showed always in Overflow

I'm using ActionBarCompat in my app, an I want to show one or two items in the action bar

I follwed the guide of google developers, but when I test it, the items are showed in the "Overflow" option (in Nexus 4) and if I tap on the menu button if there exist (ex. Galaxy S3)

What I've doing wrong?

SOLUTION FOUND

You can find it in a answer.

like image 550
Shudy Avatar asked Aug 26 '13 20:08

Shudy


1 Answers

I had the same problem, and found two solutions:

In the menu xml (Login.xml), use your app name for the showAsAction tag:

instead of:

<item
    android:id="@+id/action_register"
    android:showAsAction="always"
    android:icon="@drawable/some_icon"
    android:title="@string/login_menu_register" />

use:

<item
    android:id="@+id/action_register"
    yourappname:showAsAction="always"
    android:icon="@drawable/some_icon"
    android:title="@string/login_menu_register" />

I suppose your application's name is shady.

the second solution for me, on the activity class, at the onCreateOptionsMenu()

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem registerMenuItem = menu.findItem(R.id.action_register);
    registerMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); // change this in backcompat
    return true;
}

if you are using backCompatibility, change last line:

MenuItemCompat.setShowAsAction(registerMenuItem,MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
like image 134
El Abogato Avatar answered Oct 25 '22 16:10

El Abogato