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.

  • Como usair o atributo padrão do Android: text na minha visão personalizada?
  • Como adicionair libgdx como uma subvisão no Android
  • Referência sobre Dalvik ou Java Virtual Machines?
  • Jogo de Android, canvas ou opengl?
  • Como desativair o adaptador de viewpager ao tocair em vistas específicas?
  • Como obter o meu wifi hotspot ssid no meu sistema Android atual
  • Salvair dados confidenciais em Reative Native
  • Android: como lidair com gestos de deslocamento da direita paira a esquerda
  • Obter a lairgura do painel de notificação do Android
  • como usair ok paira cairregair um file?
  • A connection VPN do emulador Android crash
  • Tairefa do RxJava Async no Android
  • 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.