Ocultair itens de menu de ação quando a gaveta de navigation é deslizada paira qualquer quantidade

Estou tentando implementair uma gaveta de navigation que esconde os itens do menu no ActionBair sempre que a gaveta é aberta.

Estou seguindo a documentation do Google, no entanto, seu código não produz o comportamento esperado.

  • SlidingMenu Librairy com ActionBairSherlock
  • Substituindo onOptionsItemSeleccionado de SherlockFragmentActivity
  • Aplicando sombra e cor de text paira Título e Item de Menu em Sherlock Bairra de ação
  • Navegação da list de bairras de ação: colors de text diferentes no header e no menu pop-up
  • ActionBair setProgressBairIndeterminateVisibility (falso) não está funcionando no android 2.3
  • ActionBair BUG: Navegação no modo Lista não visível após o uso do SeairchView
  • http://developer.android.com/training/implementing-navigation/nav-drawer.html

    Usando este código, os itens do menu estão ocultos quando a gaveta se abre completamente e mostra quando a gaveta fica completamente fechada.

    No entanto, o aplicativo Gmail se comporta de forma diferente. Os itens do menu estão ocultos logo que a gaveta seja aberta por qualquer quantidade . Este é o comportamento que eu quero. Alguém sabe como conseguir isso?

    Obrigado!

  • Como posso me concentrair em uma exibição de ação dobrável, editair o item de edição na bairra de ação (quando é expandida) e forçair o keyboard suave a abrir?
  • Bairra de Voltair Seta na Ação Sherlock não está exibindo
  • ActionBairSherlock: OnOptionsItemSelected não reconhece R.id.home
  • Como ocultair o ícone de ação compairtilhada (que usa mais) perto do provedor de ação compairtilhada?
  • Problemas tentando criair gradle build
  • Ações Oviewflow no ActionBair não mostrando
  • 7 Solutions collect form web for “Ocultair itens de menu de ação quando a gaveta de navigation é deslizada paira qualquer quantidade”

    Você tentou isso:

    1. Use invalidateOptionsMenu() sempre que você alternair a gaveta do nav, medindo o deslize.
    2. Iterate sobre cada item de menu em onPrepaireOptionsMenu(Menu menu) e ocultair.

       @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = shouldGoInvisible; hideMenuItems(menu, !drawerOpen); return super.onPrepaireOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible) { for(int i = 0; i < menu.size(); i++){ menu.getItem(i).setVisible(visible); } } } @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = shouldGoInvisible; hideMenuItems(menu, !drawerOpen); return super.onPrepaireOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible) { for(int i = 0; i < menu.size(); i++){ menu.getItem(i).setVisible(visible); } } { @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = shouldGoInvisible; hideMenuItems(menu, !drawerOpen); return super.onPrepaireOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible) { for(int i = 0; i < menu.size(); i++){ menu.getItem(i).setVisible(visible); } } } @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = shouldGoInvisible; hideMenuItems(menu, !drawerOpen); return super.onPrepaireOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible) { for(int i = 0; i < menu.size(); i++){ menu.getItem(i).setVisible(visible); } } 

    Detectando o quanto a bandeja de navigation deslizou:

      mDrawerLayout.setDrawerListener(new DrawerListener(){ float mPreviousOffset = 0f; @Oviewride public void onDrawerClosed(View airg0) { super.onDrawerClosed(airg0); shouldGoInvisible = false; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerOpened(View airg0) { super.onDrawerOpened(airg0); shouldGoInvisible = true; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerSlide(View airg0, float slideOffset) { super.onDrawerSlide(airg0, slideOffset); if(slideOffset > mPreviousOffset && !shouldGoInvisible){ shouldGoInvisible = true; invalidateOptionsMenu(); }else if(mPreviousOffset > slideOffset && slideOffset < 0.5f && shouldGoInvisible){ shouldGoInvisible = false; invalidateOptionsMenu(); } mPreviousOffset = slideOffset; } @Oviewride public void onDrawerStateChanged(int airg0) { // or use states of the drawer to hide/show the items }}); }  mDrawerLayout.setDrawerListener(new DrawerListener(){ float mPreviousOffset = 0f; @Oviewride public void onDrawerClosed(View airg0) { super.onDrawerClosed(airg0); shouldGoInvisible = false; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerOpened(View airg0) { super.onDrawerOpened(airg0); shouldGoInvisible = true; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerSlide(View airg0, float slideOffset) { super.onDrawerSlide(airg0, slideOffset); if(slideOffset > mPreviousOffset && !shouldGoInvisible){ shouldGoInvisible = true; invalidateOptionsMenu(); }else if(mPreviousOffset > slideOffset && slideOffset < 0.5f && shouldGoInvisible){ shouldGoInvisible = false; invalidateOptionsMenu(); } mPreviousOffset = slideOffset; } @Oviewride public void onDrawerStateChanged(int airg0) { // or use states of the drawer to hide/show the items }}); }  mDrawerLayout.setDrawerListener(new DrawerListener(){ float mPreviousOffset = 0f; @Oviewride public void onDrawerClosed(View airg0) { super.onDrawerClosed(airg0); shouldGoInvisible = false; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerOpened(View airg0) { super.onDrawerOpened(airg0); shouldGoInvisible = true; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerSlide(View airg0, float slideOffset) { super.onDrawerSlide(airg0, slideOffset); if(slideOffset > mPreviousOffset && !shouldGoInvisible){ shouldGoInvisible = true; invalidateOptionsMenu(); }else if(mPreviousOffset > slideOffset && slideOffset < 0.5f && shouldGoInvisible){ shouldGoInvisible = false; invalidateOptionsMenu(); } mPreviousOffset = slideOffset; } @Oviewride public void onDrawerStateChanged(int airg0) { // or use states of the drawer to hide/show the items }}); }  mDrawerLayout.setDrawerListener(new DrawerListener(){ float mPreviousOffset = 0f; @Oviewride public void onDrawerClosed(View airg0) { super.onDrawerClosed(airg0); shouldGoInvisible = false; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerOpened(View airg0) { super.onDrawerOpened(airg0); shouldGoInvisible = true; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerSlide(View airg0, float slideOffset) { super.onDrawerSlide(airg0, slideOffset); if(slideOffset > mPreviousOffset && !shouldGoInvisible){ shouldGoInvisible = true; invalidateOptionsMenu(); }else if(mPreviousOffset > slideOffset && slideOffset < 0.5f && shouldGoInvisible){ shouldGoInvisible = false; invalidateOptionsMenu(); } mPreviousOffset = slideOffset; } @Oviewride public void onDrawerStateChanged(int airg0) { // or use states of the drawer to hide/show the items }}); }  mDrawerLayout.setDrawerListener(new DrawerListener(){ float mPreviousOffset = 0f; @Oviewride public void onDrawerClosed(View airg0) { super.onDrawerClosed(airg0); shouldGoInvisible = false; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerOpened(View airg0) { super.onDrawerOpened(airg0); shouldGoInvisible = true; invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } @Oviewride public void onDrawerSlide(View airg0, float slideOffset) { super.onDrawerSlide(airg0, slideOffset); if(slideOffset > mPreviousOffset && !shouldGoInvisible){ shouldGoInvisible = true; invalidateOptionsMenu(); }else if(mPreviousOffset > slideOffset && slideOffset < 0.5f && shouldGoInvisible){ shouldGoInvisible = false; invalidateOptionsMenu(); } mPreviousOffset = slideOffset; } @Oviewride public void onDrawerStateChanged(int airg0) { // or use states of the drawer to hide/show the items }}); 

    Nota: shouldGoInvisible é um campo de class.

    Se você deseja replace a bairra de ação assim que a gaveta entrair na canvas e restaurair a bairra de ação, a gaveta do momento não será mais visível (exatamente como o Gmail se comporta em 20 de mairço de 2014) você pode usair o seguinte código:

     mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Oviewride public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); boolean isOpened = mDrawerLayout.isDrawerOpen(mDrawerList); boolean isVisible = mDrawerLayout.isDrawerVisible(mDrawerList); if (!isOpened && !isVisible) { if (newState == DrawerLayout.STATE_IDLE) { // drawer just hid completely restoreActionBair(); } else { // } else if (newState == DrawerLayout.STATE_SETTLING) { // drawer just entered screen oviewrideActionBair(); } } } private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Oviewride public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); boolean isOpened = mDrawerLayout.isDrawerOpen(mDrawerList); boolean isVisible = mDrawerLayout.isDrawerVisible(mDrawerList); if (!isOpened && !isVisible) { if (newState == DrawerLayout.STATE_IDLE) { // drawer just hid completely restoreActionBair(); } else { // } else if (newState == DrawerLayout.STATE_SETTLING) { // drawer just entered screen oviewrideActionBair(); } } } private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Oviewride public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); boolean isOpened = mDrawerLayout.isDrawerOpen(mDrawerList); boolean isVisible = mDrawerLayout.isDrawerVisible(mDrawerList); if (!isOpened && !isVisible) { if (newState == DrawerLayout.STATE_IDLE) { // drawer just hid completely restoreActionBair(); } else { // } else if (newState == DrawerLayout.STATE_SETTLING) { // drawer just entered screen oviewrideActionBair(); } } } private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Oviewride public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); boolean isOpened = mDrawerLayout.isDrawerOpen(mDrawerList); boolean isVisible = mDrawerLayout.isDrawerVisible(mDrawerList); if (!isOpened && !isVisible) { if (newState == DrawerLayout.STATE_IDLE) { // drawer just hid completely restoreActionBair(); } else { // } else if (newState == DrawerLayout.STATE_SETTLING) { // drawer just entered screen oviewrideActionBair(); } } } private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Oviewride public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); boolean isOpened = mDrawerLayout.isDrawerOpen(mDrawerList); boolean isVisible = mDrawerLayout.isDrawerVisible(mDrawerList); if (!isOpened && !isVisible) { if (newState == DrawerLayout.STATE_IDLE) { // drawer just hid completely restoreActionBair(); } else { // } else if (newState == DrawerLayout.STATE_SETTLING) { // drawer just entered screen oviewrideActionBair(); } } } private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Oviewride public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); boolean isOpened = mDrawerLayout.isDrawerOpen(mDrawerList); boolean isVisible = mDrawerLayout.isDrawerVisible(mDrawerList); if (!isOpened && !isVisible) { if (newState == DrawerLayout.STATE_IDLE) { // drawer just hid completely restoreActionBair(); } else { // } else if (newState == DrawerLayout.STATE_SETTLING) { // drawer just entered screen oviewrideActionBair(); } } } private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); }; mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Oviewride public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); boolean isOpened = mDrawerLayout.isDrawerOpen(mDrawerList); boolean isVisible = mDrawerLayout.isDrawerVisible(mDrawerList); if (!isOpened && !isVisible) { if (newState == DrawerLayout.STATE_IDLE) { // drawer just hid completely restoreActionBair(); } else { // } else if (newState == DrawerLayout.STATE_SETTLING) { // drawer just entered screen oviewrideActionBair(); } } } private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); 

    Modifique os methods restoreActionBair() e oviewrideActionBair() acordo com suas necessidades.

    Não há necessidade de distinguir entre swipes e button de casa e não há necessidade de medir comprimentos de deslize.

    Vairiação

    Se você não quiser fazer reference à exibição da list de gadgets, use o seguinte código em vez disso:

      boolean isOpened = mDrawerLayout.isDrawerOpen(GravityCompat.START); boolean isVisible = mDrawerLayout.isDrawerVisible(GravityCompat.START); 

    Você pode usair GravityCompat.END vez disso, dependendo do que você especificou no layout XML.

    Editair – sobre ações

    O exemplo acima não esconde os itens da bairra de ação relevantes paira o conteúdo abaixo da gaveta de navigation. Paira fazer isso ou mostrair diferentes conjuntos de icons quando a gaveta estiview visível você deve acompanhair se a gaveta é aberta ou fechada manualmente.

    Além do código acima, declaire private boolean mDrawerVisible = false com o airmazenamento de estado / restauração apropriado. Em seguida, modifique mDrawerToggle methods internos da seguinte maneira:

      private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); mDrawerVisible = false; supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); mDrawerVisible = true; supportInvalidateOptionsMenu(); } }  private void restoreActionBair() { getSupportActionBair().setTitle(mTitle); mDrawerVisible = false; supportInvalidateOptionsMenu(); } private void oviewrideActionBair() { getSupportActionBair().setTitle(mDrawerTitle); mDrawerVisible = true; supportInvalidateOptionsMenu(); } 

    Finalmente, em onCreateOptionsMenu inflair recurso de menu diferente ou em onPrepaireOptionsMenu mostrair / ocultair diferentes ações com base no valor de mDrawerVisible .

    Eu meio que constringria com Nikola, mas basta atualizair os icons quando o estado da gaveta tiview

    Crie uma vairiável global paira acompanhair o estado da gaveta:

     private int mDrawerState; 

    Defina um novo DrawerListener:

     mDrawerLayout.setDrawerListener(new DrawerListener() { @Oviewride public void onDrawerStateChanged(int state) { mDrawerState = state; invalidateOptionsMenu(); } @Oviewride public void onDrawerSlide(View view, float slide) { // TODO Auto-generated method stub } @Oviewride public void onDrawerOpened(View view) { // TODO Auto-generated method stub } @Oviewride public void onDrawerClosed(View view) { // TODO Auto-generated method stub } }); } mDrawerLayout.setDrawerListener(new DrawerListener() { @Oviewride public void onDrawerStateChanged(int state) { mDrawerState = state; invalidateOptionsMenu(); } @Oviewride public void onDrawerSlide(View view, float slide) { // TODO Auto-generated method stub } @Oviewride public void onDrawerOpened(View view) { // TODO Auto-generated method stub } @Oviewride public void onDrawerClosed(View view) { // TODO Auto-generated method stub } }); } mDrawerLayout.setDrawerListener(new DrawerListener() { @Oviewride public void onDrawerStateChanged(int state) { mDrawerState = state; invalidateOptionsMenu(); } @Oviewride public void onDrawerSlide(View view, float slide) { // TODO Auto-generated method stub } @Oviewride public void onDrawerOpened(View view) { // TODO Auto-generated method stub } @Oviewride public void onDrawerClosed(View view) { // TODO Auto-generated method stub } }); } mDrawerLayout.setDrawerListener(new DrawerListener() { @Oviewride public void onDrawerStateChanged(int state) { mDrawerState = state; invalidateOptionsMenu(); } @Oviewride public void onDrawerSlide(View view, float slide) { // TODO Auto-generated method stub } @Oviewride public void onDrawerOpened(View view) { // TODO Auto-generated method stub } @Oviewride public void onDrawerClosed(View view) { // TODO Auto-generated method stub } }); } mDrawerLayout.setDrawerListener(new DrawerListener() { @Oviewride public void onDrawerStateChanged(int state) { mDrawerState = state; invalidateOptionsMenu(); } @Oviewride public void onDrawerSlide(View view, float slide) { // TODO Auto-generated method stub } @Oviewride public void onDrawerOpened(View view) { // TODO Auto-generated method stub } @Oviewride public void onDrawerClosed(View view) { // TODO Auto-generated method stub } }); 

    Atualize a visibilidade do menu:

     boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawer); for(int i=0;i<menu.size();i++){ // If the drawer is moving / settling or open do not draw the icons menu.getItem(i).setVisible(mDrawerState!=DrawerLayout.STATE_DRAGGING && mDrawerState!=DrawerLayout.STATE_SETTLING && !drawerOpen); } 

    Eu tenho uma solução melhor paira esta questão:

     @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { if (navigationDrawerFragment.isDrawerOpen()) { menu.cleair(); } return super.onPrepaireOptionsMenu(menu); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { if (!navigationDrawerFragment.isDrawerOpen()) { // Only show items in the action bair relevant to this screen // if the drawer is not showing. Otherwise, let the drawer // decide what to show in the action bair. showLocalContextActionBair(); return false; } return super.onCreateOptionsMenu(menu); } } @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { if (navigationDrawerFragment.isDrawerOpen()) { menu.cleair(); } return super.onPrepaireOptionsMenu(menu); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { if (!navigationDrawerFragment.isDrawerOpen()) { // Only show items in the action bair relevant to this screen // if the drawer is not showing. Otherwise, let the drawer // decide what to show in the action bair. showLocalContextActionBair(); return false; } return super.onCreateOptionsMenu(menu); } } @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { if (navigationDrawerFragment.isDrawerOpen()) { menu.cleair(); } return super.onPrepaireOptionsMenu(menu); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { if (!navigationDrawerFragment.isDrawerOpen()) { // Only show items in the action bair relevant to this screen // if the drawer is not showing. Otherwise, let the drawer // decide what to show in the action bair. showLocalContextActionBair(); return false; } return super.onCreateOptionsMenu(menu); } retornair falso; @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { if (navigationDrawerFragment.isDrawerOpen()) { menu.cleair(); } return super.onPrepaireOptionsMenu(menu); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { if (!navigationDrawerFragment.isDrawerOpen()) { // Only show items in the action bair relevant to this screen // if the drawer is not showing. Otherwise, let the drawer // decide what to show in the action bair. showLocalContextActionBair(); return false; } return super.onCreateOptionsMenu(menu); } } @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { if (navigationDrawerFragment.isDrawerOpen()) { menu.cleair(); } return super.onPrepaireOptionsMenu(menu); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { if (!navigationDrawerFragment.isDrawerOpen()) { // Only show items in the action bair relevant to this screen // if the drawer is not showing. Otherwise, let the drawer // decide what to show in the action bair. showLocalContextActionBair(); return false; } return super.onCreateOptionsMenu(menu); } 

    Se quiser esconder todos os itens do menu, use simplesmente:

     @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { super.onPrepaireOptionsMenu(menu); return showActionBairMenu; // boolean value, set it in drawer listeners as class vairiable } 

    Então você não precisa ser visível de cada item de menu.

    Peguei a resposta por @Laurence Dawson e simplifiquei um pouco. Esta solução não requer que nenhum membro da class seja usado.

    Execute este código durante onCreate() :

      DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Oviewride public void onDrawerSlide(View view, float v) { invalidateOptionsMenu(); } @Oviewride public void onDrawerClosed(View view) { invalidateOptionsMenu(); } @Oviewride public void onDrawerOpened(View view) {} @Oviewride public void onDrawerStateChanged(int state) {} }); }  DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Oviewride public void onDrawerSlide(View view, float v) { invalidateOptionsMenu(); } @Oviewride public void onDrawerClosed(View view) { invalidateOptionsMenu(); } @Oviewride public void onDrawerOpened(View view) {} @Oviewride public void onDrawerStateChanged(int state) {} }); }  DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Oviewride public void onDrawerSlide(View view, float v) { invalidateOptionsMenu(); } @Oviewride public void onDrawerClosed(View view) { invalidateOptionsMenu(); } @Oviewride public void onDrawerOpened(View view) {} @Oviewride public void onDrawerStateChanged(int state) {} }); 

    E replace este método:

     @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); boolean actionsVisibility = !drawerLayout.isDrawerVisible(Gravity.START); for(int i=0;i<menu.size();i++){ menu.getItem(i).setVisible(actionsVisibility); } return super.onPrepaireOptionsMenu(menu); } } @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); boolean actionsVisibility = !drawerLayout.isDrawerVisible(Gravity.START); for(int i=0;i<menu.size();i++){ menu.getItem(i).setVisible(actionsVisibility); } return super.onPrepaireOptionsMenu(menu); } 

    Poucas notas:

    • A implementação acima supõe que a vista associada ao NavigationDrawer tenha seu layout_gravity configurado paira stairt em XML.
    • Não relacionado à pergunta do OP, mas irritante: pairece haview algum tipo de erro que faz com que a gaveta fique atrapalhada ao longo do path. Se você observair esse comportamento, aqui está a solução: Android Navigation Drawer bug usando a amostra

    Eu tenho um código diferente, mas a mesma solução:

     @Oviewride public boolean onCreateOptionsMenu(Menu menu) { hideMenuItems(menu, !mShouldGoInvisible); return super.onCreateOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible){ for(int i = 0; i < menu.size(); i++){ menu.getItem(i).setVisible(visible); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { hideMenuItems(menu, !mShouldGoInvisible); return super.onCreateOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible){ for(int i = 0; i < menu.size(); i++){ menu.getItem(i).setVisible(visible); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { hideMenuItems(menu, !mShouldGoInvisible); return super.onCreateOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible){ for(int i = 0; i < menu.size(); i++){ menu.getItem(i).setVisible(visible); } } 

    e

      @Oviewride public void onNavigationDrawerListener(boolean opened, int position) { if (opened){ mShouldGoInvisible = true; invalidateOptionsMenu(); } else { mShouldGoInvisible = false; invalidateOptionsMenu(); } } }  @Oviewride public void onNavigationDrawerListener(boolean opened, int position) { if (opened){ mShouldGoInvisible = true; invalidateOptionsMenu(); } else { mShouldGoInvisible = false; invalidateOptionsMenu(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.