0
votes

I have a menu defined in an XML file such a "home_menu.xml" like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
<!-- Should always be in the overflow -->
<item
    android:id="@+id/action_settings"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
<item
    android:id="@+id/action_user_preferences"
    android:showAsAction="never"
    android:title="@string/action_user_preferences"/>
<item
    android:id="@+id/action_logout" 
    android:showAsAction="never"
    android:title="@string/action_logout"/>

</menu>

In my "Home" activity, I can access this menu by pushing the menu button in a device that has a physical button, but I don't want to use action bar so I want to add a Navigation Drawer for this purpose as Google Maps does.

It would be great if I could use the same onOptionsItemSelected() method defined in my Home activity to handle menu actions.

1

1 Answers

0
votes

You won't be able to do that.

You'll have to do it manually.

Or semi-manually. You could in onCreateOptionsMenu get all the menu items with title, icon and id and generate the view (listview for instance) for the drawer. And use a shared method to handle the click that takes the id in parameter. But if you want to hide/show some elements in the menu, you'll have to update your listview manually since onCreateOptionsMenu won't be called. And if you have multiple fragment with menus you'll also have to do something.

So I would recommend to use the drawer even when there is a hardware menu key.