2

J'ajoute une vue personnalisée à la barre d'action mais lorsque je le fais, l'icône de l'indicateur de navigation ne s'affiche pas. Lorsque je n'affiche pas l'affichage personnalisé, l'indicateur s'affiche et fonctionne correctement.Android Action Bar Affichage personnalisé Indicateur de navigation caché

getActionBar().setDisplayHomeAsUpEnabled(true); 
    getActionBar().setHomeButtonEnabled(true); 
    getActionBar().setBackgroundDrawable(getResources().getDrawable(navConf.getBackgroundDraw())); 

    if (0 != navConf.getActionBarCustomView()){ 
     getActionBar().setCustomView(navConf.getActionBarCustomView()); 
     getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM 
       | ActionBar.DISPLAY_SHOW_HOME); 
    } 

    try{ 
     mDrawerToggle = new ActionBarDrawerToggle(
       this, 
       mDrawerLayout, 
       navConf.getDrawerIcon(), 
       navConf.getDrawerOpenDesc(), 
       navConf.getDrawerCloseDesc() 
       ) { 
      public void onDrawerClosed(View view) { 
       getActionBar().setTitle(mTitle); 
       ActivityCompat.invalidateOptionsMenu(AbstractNavDrawerActivity.this); 
      } 

      public void onDrawerOpened(View drawerView) { 
       getActionBar().setTitle(mDrawerTitle); 
       ActivityCompat.invalidateOptionsMenu(AbstractNavDrawerActivity.this); 
      } 
     }; 
    } 
    catch (Exception ex){ 
     Log.e("ActionBarDrawerToggle: ", ex.toString()); 
    } 

    mDrawerLayout.setDrawerListener(mDrawerToggle); 

Répondre

0
getActionBar().setDisplayShowCustomEnabled(true); 
    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    getActionBar().setIcon(R.mipmap.icon_menu); 
    getActionBar().setCustomView(getLayoutInflater().inflate(R.layout.actionbar_main, null), 
      new ActionBar.LayoutParams(
        ActionBar.LayoutParams.WRAP_CONTENT, 
        ActionBar.LayoutParams.MATCH_PARENT, 
        Gravity.CENTER 
      ) 
    ); 
    getActionBar().setDisplayHomeAsUpEnabled(true); 
    getActionBar().setHomeButtonEnabled(true); 
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
      R.mipmap.icon_menu, //nav menu toggle icon 
      0, // nav drawer open - description for accessibility 
      0 // nav drawer close - description for accessibility 
    ) { 
     public void onDrawerClosed(View view) { 
      getActionBar().setTitle(mTitle); 
      // calling onPrepareOptionsMenu() to show action bar icons 
      invalidateOptionsMenu(); 
     } 

     public void onDrawerOpened(View drawerView) { 
      getActionBar().setTitle(mDrawerTitle); 
      // calling onPrepareOptionsMenu() to hide action bar icons 
      invalidateOptionsMenu(); 
     } 
    }; 
+0

Peut-être que vous voulez écrire quelques mots supplémentaires pour cette solution? –

0

Ajouter ce drapeau comme une option d'affichage ActionBar:

ActionBar.DISPLAY_HOME_AS_UP