Android.support.v7 Toolbar & DrawerLayout- cómo ocultar icono de Hamburger
Tengo mi propio menú (hamburguesa) icono en mi barra de herramientas para abrir el cajón de navegación y estoy mostrando insignia contar en mi icono de menú (Hamburger). Así que me gustaría ocultar icono de Hamburger por defecto.
He intentado de esta manera:
- Android: ¿Cómo puedo evitar que DrawerLayout pase eventos táctiles a la vista subyacente
- ¿Cómo mostrar el DrawerLayout cuando se desliza de izquierda a derecha, no importa dónde?
- Cómo crear DrawerLayout programaticamente
- Necesita hacer la vista de lista en el centro verticalmente para Disposición de cajones en Android
- Autocompletar no funciona en archivos XML en una jerarquía particular
getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
Por favor, ayúdenme. Gracias de antemano.
- ¿Cómo puedo hacer que DrawerLayout se muestre debajo de la barra de herramientas?
- Android DrawerLayout no funciona con ViewPager?
- Cómo configurar el icono de Disposición de cajones en el lado derecho de la pantalla del dispositivo?
- El botón dentro de DrawerLayout no se puede hacer clic
- Por qué no puedo bloquear DrawerLayout con gravedad de diseño
- Android DrawerLayout y Listview con adaptador personalizado
- Toggle DrawerLayout con solo título (NO Icono de la aplicación)?
- El método setDrawerListener está obsoleto
Llamada .setDrawerIndicatorEnabled(false);
En su ActionBarDrawerToggle
Esto funciona para mí:
public void setLogo(String imageUrl) { ViewGroup toolbarView = (ViewGroup) toolbar.findViewById(R.id.toolbar); // set an arbitrary logo so the support library adds an ImageView to the toolbar. // without this, there would be no ImageView elements in the toolbar // and the following loop would not work // `empty_drawable` is a simple rectangle of size 100x100 with a bg color // matching that of the toolbar // the size really matters because the smaller you set this image, the next logo // you set will be of that size. If your arbitrary drawable is of size 1x1, then // the next logo you set will be of the same size. At least that is what happens // for me when I load an image with Glide. // Your drawable should have a background color too. I chose the toolbar's // background color. If you don't set a background color, your app would crash on Kitkat. toolbar.setLogo(R.drawable.empty_drawable); for (int i = 0; i < toolbarView.getChildCount(); i++) { if ((toolbarView.getChildAt(i) instanceof ImageView)) { ImageView logoView = (ImageView) toolbarView.getChildAt(i); if (!TextUtils.isEmpty(imageUrl)) { // this way I can download an image and set the logo that way Glide.with(MainActivity.this).load(imageUrl).into(logoView); // I do this because there is no space between logo and the toolbar title logoView.setPadding(0, 0, 30, 0); // and this is because of the `else` block logoView.setVisibility(View.VISIBLE); } else { // pass null to `setLogo()` to hide the logo logoView.setVisibility(View.GONE); logoView.setPadding(0, 0, 0, 0); } break; } } }
Y esta es mi barra de herramientas:
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:animateLayoutChanges="true" app:popupTheme="@style/AppTheme.PopupOverlay" app:title="@string/app_name" tools:ignore="UnusedAttribute" />
El android:animateLayoutChanges="true"
parte hace que todo esto sea realmente agradable. Y tools:ignore="UnusedAttribute"
es porque el SDK mínimo de mi aplicación está establecido en 9.
Pruebe esto en la actividad onCreate:
getActionBar().setIcon( new ColorDrawable(getResources().getColor(android.R.color.transparent)));
Si está utilizando AppCompat, reemplace getActionBar
por getSupportActionBar
.