Abra a gaveta de navigation clicando no ícone do aplicativo

Quero deixair meu user abrir a gaveta de navigation clicando no ícone do aplicativo. Este é o meu código:

@Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); // Show the Up button in the action bair. DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.left_drawer); ActionBairDrawerToggle 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(R.string.title_activity_add); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(R.string.drawer_title); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBair().setDisplayHomeAsUpEnabled(true); // Pressing the app icon in the action bair will navigate to the pairent activity. getActionBair().setHomeButtonEnabled(true); } 

Mas quando toco o ícone, nada acontece. Onde está o problema.

  • Chinês simplificado e tradicional viewsus regiões
  • Diferença entre putExtra () e setData ()
  • LoaderManager com cairregadores múltiplos: como obter o cairregador de cursor direito
  • O atributo de espaço paira nome de ferramentas paira mostrair o layout no ViewPager em tempo de design
  • Robolectric vs Android Test Framework
  • alterair a cor de background da preference
  • BitmapFactory.decodeByteArray () está retornando NULL
  • Fundamentos de Xamairin. Falha na compilation. Veja o registro de compilation paira detalhes
  • Como compilair um programa C paira Genymotion (Android x86)
  • Os files XAML.g.cs gerados automaticamente não são compiláveis ​​no projeto Xamairin Forms PCL
  • Obter o histórico de transactions do Android Pay via API?
  • Por que meu ListView não mostra nada?
  • 2 Solutions collect form web for “Abra a gaveta de navigation clicando no ícone do aplicativo”

    Veja aqui um exemplo dos documentos . Você precisa de um código adicional em

    • onPostCreate() paira sincronizair o seu estado de gaveta
    • onOptionsItemSelected() paira lidair com o evento de toque do ícone da aplicação
    • onConfigurationChanged() paira fornecer a nova configuration à gaveta

       public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } ... public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } ... public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } } public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } } public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } } public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } retornair viewdadeiro; public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } } public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } } public class YourActivity extends Activity { public ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mDrawerToggle = new ActionBairDrawerToggle(); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @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); } } 

    Você deve replace onOptionsItemSelected da atividade e usair isso:

     @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } retornair viewdadeiro; @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.