Android Toolbar Back button with Icon and click

Toolbar with Back button

Simple code to make android tool bar back button and when clicked activity will be finished.

Toolbar with Back button
   // Toolbar
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //My Toolbar title
        TextView mTitle = toolbar.findViewById(R.id.toolbar_title);
        mTitle.setText("MY TITLE");
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        //Home button
        toolbar.setNavigationIcon(R.drawable.<YourIcon>);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

XML layout for Activity

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/yellow">

            <TextView
                android:id="@+id/toolbar_title"
                style="@style/myToolbarStyle"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="0dp" />

        </android.support.v7.widget.Toolbar>