Hide completely drawer hamburger button when in landscape mode on tablet

0

as the title says I'm trying to hide completely the hamburger button when I'm in a landscape mode on tablet, but i still want the back-arrow to be there when I enter submenus in order to get back to home screen.

This code snippet shows how i identify tablet landscape mode and other orientation

        // check the device type and shows drawer accordingly
    if (isTabletLandscape) {
        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
        drawerLayout.setScrimColor(0x00000000) // set the rest of the screen without shadow as if drawer and the rest were on the same level
    }

and this works fine, but it keeps showing me the hamburger button, which, if pressed, gives the this error:

** java.lang.IllegalArgumentException: No drawer view found with gravity LEFT **

so i think that disabling that button would solve my problems.

I already tried:

  • toolbar.setnavigationicon(null) and does not work (also with another picture of the same color of the toolbar
  • actionBarDrawerToggle.isDrawerIndicatorEnable = falseand it doesnt work
  • actionBarDrawerToggle.setHomeAsUpIndicator(null)
  • supportActionBar?.setDisplayHomeAsUpEnable(false)

but none of them actually worked.

if needed this is the .xml file that handles the drawer in large-land mode:

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
android:layout_gravity="start"
android:orientation="horizontal">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:id="@+id/nav_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="start">
        <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
</LinearLayout>

android
android-layout
kotlin
navigation-drawer
asked on Stack Overflow Apr 29, 2020 by Giorgio Maritano • edited Apr 29, 2020 by Giorgio Maritano

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0