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! While you're at it, check out some resources Treehouse students have shared here.

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

Android logout menu not showing

Hi

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

I have this in the activity:

@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) {
    int itemId = item.getItemId();

    if (itemId == R.id.action_logout) {
        ParseUser.logOut();
        navigate_to_login();

}

    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!

Michael

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..

Michael