سؤال

I want to change the actions when I select an item from the NavigationDrawer. Is that possible and what's the right way to do that? I am using an Activity that implements the NavigationDrawerFragment.

navigation/actions

Thank you

هل كانت مفيدة؟

المحلول

You can use fragments and each fragment should call setHasOptionsMenu(true); in the onCreateView() and onResume() method of that fragment. You can do this if you are using ActionBarSherlock,

getSherlockActivity().supportInvalidateOptionsMenu();

and, then, in each of your fragments build the menu with

public void onPrepareOptionsMenu(final Menu menu) {

}

this allows you to have different actions in the ActionBar for each fragment.

If you just want to change your actions from the same fragment or activity, then you should put the invalidateOptionsMenu() call in the action that was pressed. This will cause the onPrepareOptionsMenu(final Menu menu) to be recalled and that will rebuild your actions for you according to what code you have in the onPrepareOptionsMenu().

Hope this helps. If anything is unclear, please don't hesitate to ask.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top