Search code examples
androidandroid-actionbarhamburger-menu

How to add back icon with hamburger menu?


I am developing an app which needs a requirement to show a back icon with a hamburger icon and a back icon as well as shown in the below image.

enter image description here

How should I achieve this?


Solution

  • I suggest using custom toolbar like bellow

    <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <androidx.appcompat.widget.AppCompatImageView
                    android:layout_width="wrap_content"
                    android:id="@+id/mImgBack"
                    android:src="@drawable/ic_back"
                    android:layout_height="wrap_content"/>
                <androidx.appcompat.widget.AppCompatImageView
                    android:layout_width="wrap_content"
                    android:id="@+id/mImgHamburger"
                    android:src="@drawable/ic_mImgHamburger"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </androidx.appcompat.widget.Toolbar>
    

    Now after that set toolbar to your

    Toolbar toolbar = (Toolbar) findViewById(R.id.profileToolbar);
    setSupportActionBar(toolbar);
    

    and perform the action and click on your image view as you want