Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Android logout menu not showing


I can't seem to get my logout menu to display;

I have this in the activity:

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;

public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    if (itemId == R.id.action_logout) {


    return super.onOptionsItemSelected(item);


And this is the menu:

<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"> <item android:id="@+id/action_logout" android:title="@string/log_out" android:orderInCategory="100" app:showAsAction="always"/> </menu>

Should be showing right?

Thanks so much!


2 Answers

Remove the line app:showAsAction="always" from the menu xml. This line forces the option to show up on the action bar itself rather than in the menu. Other than that your code looks fine to me.

Thanks Patrick!

I've discovered the emulators display the menus in differing ways..