'Toggle button doesn't with drawer navigation

My toggle button doesn't work, when I press him I see like it is pressed but there is not action. I can open my drawer layout, it changes when swipe, but there is not action on its, why? I set custom toolbar in the fragment, I know it could be the problem there but I try to solve it for weeks and still nothing :) Thanks

Code in fragment

   private fun drawerUsage() {
        act = activity as AppCompatActivity
        act.setSupportActionBar(layout.appBarLayout)
//        act.supportActionBar!!.elevation = 0F;
        val drawer = layout.drawerLayout
        val navigationView = layout.navView
        toggle = ActionBarDrawerToggle(
            requireActivity(),
            drawer,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close
        )
        drawer.addDrawerListener(toggle)
        toggle.syncState()
        act!!.supportActionBar?.setDisplayHomeAsUpEnabled(true)

      drawer.setViewScale(Gravity.START, 0.9f);
        //set height scale for main view (0f to 1f)
        drawer.setViewElevation(Gravity.START, 20f);
        //set main view elevation when drawer open (dimension)
        drawer.setViewScrimColor(Gravity.START, Color.TRANSPARENT);
        //set drawer overlay coloe (color)
        drawer.setDrawerElevation(Gravity.START, 20f);
        //set drawer elevation (dimension
        drawer.setRadius(Gravity.START, 25f);
        //set end container's corner radius (dimension)


        navigationView.setNavigationItemSelectedListener {
            when (it.itemId) {
                R.id.t1 -> Toast.makeText(requireContext(), "Clicked Item 1", Toast.LENGTH_SHORT)
                    .show()
                R.id.t2 -> Toast.makeText(requireContext(), "Clicked Item 2", Toast.LENGTH_SHORT)
                    .show()
                R.id.t3 -> Toast.makeText(requireContext(), "Clicked Item 3", Toast.LENGTH_SHORT)
                    .show()
            }
            true
        }
}
    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (toggle.onOptionsItemSelected(item)) {
            return true
        }
        return super.onOptionsItemSelected(item)
    }
}

fragment layout

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.infideap.drawerbehavior.Advance3DDrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".fragments.ViewPagerFragment"
        tools:openDrawer="start">

        <!--    &lt;!&ndash;Toolbar&ndash;&gt;-->
        <!--        <include-->
        <!--            android:id="@+id/toolbar"-->
        <!--            layout="@layout/toolbar" />-->

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="60dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/appBarLayout">

            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </com.google.android.material.tabs.TabLayout>

            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/viewPager"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />


        </LinearLayout>

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@layout/layout_default_toolbar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            >



<!--            <com.google.android.material.appbar.MaterialToolbar-->
<!--                android:id="@+id/appBar"-->
<!--                android:layout_width="wrap_content"-->
<!--                android:layout_height="?attr/actionBarSize"-->
<!--                app:popupTheme="@style/Widget.AppCompat.PopupMenu.Overflow"-->
<!--                />-->

        </com.google.android.material.appbar.MaterialToolbar>

    </androidx.constraintlayout.widget.ConstraintLayout>

        <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:background="@color/green"
            android:fitsSystemWindows="true"
            app:elevation="0dp"
            app:itemIconPadding="10dp"
            app:itemIconTint="@android:color/white"
            app:itemTextColor="@android:color/white"
            app:headerLayout="@layout/item_header"
            app:menu="@menu/menu_drawer"

            ></com.google.android.material.navigation.NavigationView>

    </com.infideap.drawerbehavior.Advance3DDrawerLayout>
</RelativeLayout>

default layout toolbar

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.MaterialToolbar
    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:background="@color/white"
    android:layout_width="match_parent"
    android:id="@+id/toolbar"
    android:layout_height="?attr/actionBarSize">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/text_size_17"
        app:titleTextAppearance="@style/SemiBold.17"
        android:textColor="@color/text_black"
        tools:text="Learning Manager"
        android:layout_gravity="center"
        android:id="@+id/tvToolbarTitle" />

    <androidx.appcompat.widget.AppCompatImageButton
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="?android:selectableItemBackgroundBorderless"
        android:src="@drawable/ic_icon_arrow_back_black"
        tools:ignore="TouchTargetSizeCheck" />

</com.google.android.material.appbar.MaterialToolbar>

themes

    <style name="Theme.LearningManager" parent="Theme.MaterialComponents.Light.NoActionBar">

after swipe before swipe



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source