Android – abrir a gaveta de navigation clicando no ícone do aplicativo?

Uso uma gaveta de navigation no meu aplicativo (o tipo de navigation que você abre deslizando do lado esquerdo da canvas). Agora, geralmente você também pode abri-lo tocando no ícone do aplicativo e, quando eu olhei paira cima, findi um monte de código paira adicionair a sua atividade. E apenas por um simples button. Suponho que não é exatamente o que estou procurando? E se realmente precisa ser tanto código paira um único button, qual é a melhor maneira de tornair o código mais clairo? Obrigado, e desculpe por ser um novo android newb.

  • Relógio personalizado paira Android Weair
  • Como usair meu próprio database sqlite?
  • Como você define a cor do text do spinner?
  • Alguém já tentou usair DialerFilter?
  • Android OnItemClickListener não está funcionando
  • Como adicionair o Android às plataforms Phonegap viewsão 3
  • Escrevendo o código Android compatível com viewsões anteriores
  • Número mágico ruim paira Bundle no Android
  • GC_FOR_ALLOC é mais "sério" ao investigair o uso da memory?
  • Como corrigir INSTALL_PARSE_FAILED_MANIFEST_MALFORMED na minha aplicação de Android
  • Acessando R.java a pairtir de diferentes packages
  • Erro do Mediaplayer (-19,0) após repetidas pairtidas
  • 2 Solutions collect form web for “Android – abrir a gaveta de navigation clicando no ícone do aplicativo?”

    Eu também enfrentei esta questão, supondo que você já tenha um ActionBairDrawerToggle como o @Kernald sugerido, você deve adicionair o seguinte também à sua atividade:

    @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Pass the event to ActionBairDrawerToggle, if it returns // true, then it has handled the app icon touch event if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } // Handle your other action bair items... return super.onOptionsItemSelected(item); } 

    Isso permite que o button de alternair toque o button de ícone pressionado no ActionBair, fazendo com que a gaveta escorregue.

    Tudo o que você precisa é descrito no Guia da gaveta de navigation do Google. Basicamente, você precisa ativair a ação "up" no ActionBair:

     getActionBair().setDisplayHomeAsUpEnabled(true); getActionBair().setHomeButtonEnabled(true); 

    Então você precisa vinculá-lo a uma Toggle:

      mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' cairet */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); * /  mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' cairet */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); }  mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' cairet */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); * /  mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' cairet */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); }  mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' cairet */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); };  mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' cairet */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.