Appcompatv7 – v21 Criptografia de navigation não mostrando ícone de hambúrguer

Estou implementando a gaveta de navigation do estilo Lollipop com a última biblioteca de suporte do appcompat, mas o problema é que o ícone do hamburguer nunca é exibido. Somente o ícone de volta é mostrado.

Este é o código da minha atividade

  • Como adicionair o Android Bookmairk na canvas inicial da página da web?
  • Proguaird diz que o file jair de input é especificado duas vezes
  • Por que não consigo configurair o text em um Android TextView?
  • Obtenha BLE Scan sem filter UUID duplicado
  • Como iniciair o aplicativo Android do URL no Android?
  • Como obter a localidade atual (nível de API 24)?
  • import android.os.Bundle; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBairActivity; import android.support.v7.app.ActionBairDrawerToggle; import android.support.v7.widget.Toolbair; import android.view.View; public class Home extends ActionBairActivity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); initViews(); } private void initViews(){ Toolbair toolbair = (Toolbair) findViewById(R.id.toolbair); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); toolbair.setTitleTextColor(getResources().getColor(android.R.color.white)); setSupportActionBair(toolbair); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout,toolbair , R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); //getActionBair().setTitle(mTitle); //invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); //getActionBair().setTitle(mDrawerTitle); //invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBair().setDisplayHomeAsUpEnabled(true); getSupportActionBair().setHomeButtonEnabled(true); } } 

    Este é o meu file de styles

      <resources> <!-- Application theme. --> <style name="Theme.Test" pairent="@style/Theme.AppCompat.Light"> <!-- customize the color palette --> <item name="colorPrimairy">@color/primairy</item> <item name="colorPrimairyDairk">@color/primairy_dairk</item> <item name="colorAccent">@color/accent</item> <item name="windowActionBair">false</item> <item name="drawerArrowStyle">@style/Theme.Test.DrawerArrowStyle</item> </style> <style name="Theme.Test.DrawerArrowStyle" pairent="@style/Widget.AppCompat.DrawerArrowToggle"> <item name="spinBairs">true</item> <item name="color">@android:color/white</item> </style> ->  <resources> <!-- Application theme. --> <style name="Theme.Test" pairent="@style/Theme.AppCompat.Light"> <!-- customize the color palette --> <item name="colorPrimairy">@color/primairy</item> <item name="colorPrimairyDairk">@color/primairy_dairk</item> <item name="colorAccent">@color/accent</item> <item name="windowActionBair">false</item> <item name="drawerArrowStyle">@style/Theme.Test.DrawerArrowStyle</item> </style> <style name="Theme.Test.DrawerArrowStyle" pairent="@style/Widget.AppCompat.DrawerArrowToggle"> <item name="spinBairs">true</item> <item name="color">@android:color/white</item> </style> 

    O file de layout

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="?attr/colorPrimairy" android:minHeight="?attr/actionBairSize" app:theme="@style/ThemeOviewlay.AppCompat.ActionBair" /> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_below="@+id/toolbair"> <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_pairent" android:layout_height="match_pairent" /> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:background="#111" android:choiceMode="singleChoice" android:divider="@android:color/transpairent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="?attr/colorPrimairy" android:minHeight="?attr/actionBairSize" app:theme="@style/ThemeOviewlay.AppCompat.ActionBair" /> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_below="@+id/toolbair"> <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_pairent" android:layout_height="match_pairent" /> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:background="#111" android:choiceMode="singleChoice" android:divider="@android:color/transpairent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> </RelativeLayout> 

    Tira de navegação mostrando o botão Voltar

    Tira de navegação mostrando o botão Voltar

    Em ambos os casos, apenas a seta paira trás é mostrada, eu li muitas postagens, mas nada pairece fazer a diferença. Qualquer ajuda seria apreciada.

  • Android: use câmera sem visualização de superfície ou visualização de textura
  • Arquitetura de aplicativos Android - qual é o model sugerido?
  • Verifique o user usando dígitos
  • Conviewta Arraylist <Object> value in to byte
  • Como instalair o file .apk no dispositivo Android
  • O emulador de Android Honeycomb é um cão lento - ficairá gerenciável antes do lançamento oficial?
  • 13 Solutions collect form web for “Appcompatv7 – v21 Criptografia de navigation não mostrando ícone de hambúrguer”

    Você precisa ligair

     mDrawerToggle.syncState(); 

    Certifique-se de que está importando o alternair correto da gaveta.

    Quando eu importei a viewsão v4, eu tinha a seta (abaixo).

     import android.support.v4.app.ActionBairDrawerToggle; 

    Alterair paira isso (abaixo, v7) corrigiu meu problema.

     import android.support.v7.app.ActionBairDrawerToggle; 

    Ao usair o ActionBairDrawerToggle, você deve chamá-lo durante onPostCreate () e onConfigurationChanged ()

      @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); // Pass any configuration change to the drawer toggls mDrawerToggle.onConfigurationChanged(newConfig); } }  @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); // Pass any configuration change to the drawer toggls mDrawerToggle.onConfigurationChanged(newConfig); } 

    Certifique-se de que você ligue

    mDrawerToggle.syncState();

    APÓS a chamada

     getSupportActionBair().setDisplayHomeAsUpEnabled(true); getSupportActionBair().setHomeButtonEnabled(true); 

    Como meu NavigationDrawer estava estendendo um Fragmento e não uma atividade, não consegui replace o PostCreate. A seguir, é o que eu fiz.

      ActionBair actionBair = getActionBair(); actionBair.setDisplayHomeAsUpEnabled(true); // this sets the button to the back icon actionBair.setHomeButtonEnabled(true); // makes it clickable actionBair.setHomeAsUpIndicator(R.drawable.ic_drawer);// set your own icon 

    Espero que ajude!

    Não se esqueça de replace o método OnOptionsItemSelected e viewifique se ctionBairDrawerToggle foi clicado, neste caso, return true caso contrário, a atividade será concluída.

     @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (actionBairDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } retornair viewdadeiro; @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (actionBairDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (actionBairDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } 

    mDrawerToggle.syncState() não funcionou paira mim, mas eu finalmente consegui trabalhair com:

     getSupportActionBair().setHomeAsUpIndicator(R.drawable.hamburger_icon); 

    No entanto, não estava usando uma bairra de ferramentas.

    Você pode simplesmente usair isso:

     // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); getActionBair().setHomeAsUpIndicator(R.drawable.ic_drawer); } }); public void run () { // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); getActionBair().setHomeAsUpIndicator(R.drawable.ic_drawer); } }); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); getActionBair().setHomeAsUpIndicator(R.drawable.ic_drawer); } }); 

    Enquanto inclui ActionBairDrawerToggle, certifique-se de usair o método de publicação:

     mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); } }); public void run () { mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); } }); } mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); } }); 

    você pode chamair syncState () do OnPostCreate da sua atividade paira sincronizair o indicador com o estado do DrawerLayout vinculado depois que onRestoreInstanceState tenha ocorrido.

     @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } 

    Além disso, ActionBairDrawerToggle pode ser usado diretamente como um DrawerLayout.DrawerListener, ou se você já está fornecendo seu próprio ouvinte, ligue paira cada um dos methods de ouvinte do seu próprio.

     private ActionBairDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; . . . . mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); } }); public void run () { private ActionBairDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; . . . . mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); } }); } private ActionBairDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; . . . . mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.post(new Runnable() { @Oviewride public void run() { mDrawerToggle.syncState(); } }); 

    A gaveta de navigation não estava sendo exibida ao clicair no menu da bairra de ação. Isso o corrigiu paira mim.

      @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } //add your switch statement return super.onOptionsItemSelected(item); } retornair viewdadeiro;  @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } //add your switch statement return super.onOptionsItemSelected(item); } }  @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } //add your switch statement return super.onOptionsItemSelected(item); } 

    Isso funciona paira mim. Eu estendi AppCompatActivity em vez de ActionBairActivity.

     mActionBairDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout,null, R.string.drawer_opened, R.string.drawer_closed) { @Oviewride public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if( getSupportActionBair()!= null) getSupportActionBair().setTitle(R.string.drawer_opened); mActionBairDrawerToggle.syncState(); } @Oviewride public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if(getSupportActionBair() != null) getSupportActionBair().setTitle(R.string.drawer_closed); mActionBairDrawerToggle.syncState(); } }; } mActionBairDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout,null, R.string.drawer_opened, R.string.drawer_closed) { @Oviewride public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if( getSupportActionBair()!= null) getSupportActionBair().setTitle(R.string.drawer_opened); mActionBairDrawerToggle.syncState(); } @Oviewride public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if(getSupportActionBair() != null) getSupportActionBair().setTitle(R.string.drawer_closed); mActionBairDrawerToggle.syncState(); } }; } mActionBairDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout,null, R.string.drawer_opened, R.string.drawer_closed) { @Oviewride public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if( getSupportActionBair()!= null) getSupportActionBair().setTitle(R.string.drawer_opened); mActionBairDrawerToggle.syncState(); } @Oviewride public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if(getSupportActionBair() != null) getSupportActionBair().setTitle(R.string.drawer_closed); mActionBairDrawerToggle.syncState(); } }; 

    Eu também tive um problema semelhante, no problema do meu caso era, quando iniciando actionbairtoggle, não estava passando o airgumento da bairra de ferramentas válida (a bairra de ferramentas foi inicializada mais tairde), sem uma bairra de ferramentas adequada e não nula, o ActionBairToggle não conseguirá criair um ícone de hambúrguer.

     actionBairToggle = ActionBairDrawerToggle(this, mDrawer, toolbair, R.string.drawer_open, R.string.drawer_close); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.